Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Manupulating Columns of datatable

Manupulating Columns of datatable

Scheduled Pinned Locked Moved ASP.NET
csharpdatabase
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kris_viswa
    wrote on last edited by
    #1

    Hi experts I have designed my page to allow users to upload excel/csv files and I am interested to capture the data from only few columns of these files. The column names of the files varies from user to user hence i created the form to obtain the column names of user's file for mapping to my database. Now my requirement is that I want to first read the column names of uploaded file and retain only columns and data which are matching to the user entered column names for mapping. clues or guidance solicited preferably in vb.net thanks in advance kris

    P 1 Reply Last reply
    0
    • K kris_viswa

      Hi experts I have designed my page to allow users to upload excel/csv files and I am interested to capture the data from only few columns of these files. The column names of the files varies from user to user hence i created the form to obtain the column names of user's file for mapping to my database. Now my requirement is that I want to first read the column names of uploaded file and retain only columns and data which are matching to the user entered column names for mapping. clues or guidance solicited preferably in vb.net thanks in advance kris

      P Offline
      P Offline
      Pranay Rana
      wrote on last edited by
      #2

      Do following code you can read all data in datatable which easily fill you requirement FileInfo fileinfo = new FileInfo(filePath); string strSql = "SELECT * FROM [" + fileinfo.Name + "]"; string strCSVConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileinfo.Directory.FullName + ";" + "Extended Properties='text;HDR=No;'"; OleDbDataAdapter oleda = new OleDbDataAdapter(strSql, strCSVConnString); DataTable dtbCSV = new DataTable(); oleda.Fill(dtbCSV);

      K 1 Reply Last reply
      0
      • P Pranay Rana

        Do following code you can read all data in datatable which easily fill you requirement FileInfo fileinfo = new FileInfo(filePath); string strSql = "SELECT * FROM [" + fileinfo.Name + "]"; string strCSVConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileinfo.Directory.FullName + ";" + "Extended Properties='text;HDR=No;'"; OleDbDataAdapter oleda = new OleDbDataAdapter(strSql, strCSVConnString); DataTable dtbCSV = new DataTable(); oleda.Fill(dtbCSV);

        K Offline
        K Offline
        kris_viswa
        wrote on last edited by
        #3

        Hi pranay thanks for response. what you explained is all about connection and fetching data to data table which is ok. My actual requirement starts there after. I would like to explain the requirements stepwise here 1.Establishing connection to db and populating data table 2.Reading the column names of the data table and retaining only columns and data which user has specified as mapping fields in page, which too may not be in sequence. 3.Adding few more columns dynamically to data table with default values 4.finally binding data to grid for user editing and final saving to db thanks kris

        P 1 Reply Last reply
        0
        • K kris_viswa

          Hi pranay thanks for response. what you explained is all about connection and fetching data to data table which is ok. My actual requirement starts there after. I would like to explain the requirements stepwise here 1.Establishing connection to db and populating data table 2.Reading the column names of the data table and retaining only columns and data which user has specified as mapping fields in page, which too may not be in sequence. 3.Adding few more columns dynamically to data table with default values 4.finally binding data to grid for user editing and final saving to db thanks kris

          P Offline
          P Offline
          Pranay Rana
          wrote on last edited by
          #4

          In that case I think first row in csv file must be name of columns. So for that read csv file in the data table. Than create you dynamic table by looping through fist row of your data table and create one dynamic datatable in between that by comparing selected row. Than loop through other rows similar fashion and read whole file and insert data row in datatable created by you. I hope that this will work for you.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups