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. CSV file to new datatable in c#?

CSV file to new datatable in c#?

Scheduled Pinned Locked Moved ASP.NET
questioncsharpcsshelp
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.
  • H Offline
    H Offline
    HyVong
    wrote on last edited by
    #1

    Help! asap, i'm uploading a csv file, that use comma as delimiter, and now how do i put the file into a new datatable? and csv/datatable file will be displayed on a grid. Any one has C# code sample will be greatly appreciate. Anyone...?:( *HyVong*

    V 1 Reply Last reply
    0
    • H HyVong

      Help! asap, i'm uploading a csv file, that use comma as delimiter, and now how do i put the file into a new datatable? and csv/datatable file will be displayed on a grid. Any one has C# code sample will be greatly appreciate. Anyone...?:( *HyVong*

      V Offline
      V Offline
      VenkatFor NET
      wrote on last edited by
      #2

      I am not sure if there any direct methods to dump the data into a Datatable. But, the efficient way could be to write your own parser which will read CSV and make an XML and use LoadXML of the dataset. The advantage would be, you can validate this XML against the schema might have in your dataset. So that, the data would be valid before dumping. Bhaskara

      H 1 Reply Last reply
      0
      • V VenkatFor NET

        I am not sure if there any direct methods to dump the data into a Datatable. But, the efficient way could be to write your own parser which will read CSV and make an XML and use LoadXML of the dataset. The advantage would be, you can validate this XML against the schema might have in your dataset. So that, the data would be valid before dumping. Bhaskara

        H Offline
        H Offline
        HyVong
        wrote on last edited by
        #3

        thanx, i actually used a method to read the file, but i have this problem, and i don't know what are the posibilies can cause this. FileStream fs = new FileStream(Server.MapPath(servFileName), FileMode.Open,FileAccess.Read); StreamReader reader = new System.IO.StreamReader(fs); try { //servFileName is the variable carry my file name reader = new System.IO.StreamReader(servFileName); while reader.ReadLine() != null) { //pass the row to the datatable } } catch {} *** the problem is it never goes to the WHILE loop, and i don't what the line above it causes the error. Anyone has any idea, please help. :( *HyVong*

        H 1 Reply Last reply
        0
        • H HyVong

          thanx, i actually used a method to read the file, but i have this problem, and i don't know what are the posibilies can cause this. FileStream fs = new FileStream(Server.MapPath(servFileName), FileMode.Open,FileAccess.Read); StreamReader reader = new System.IO.StreamReader(fs); try { //servFileName is the variable carry my file name reader = new System.IO.StreamReader(servFileName); while reader.ReadLine() != null) { //pass the row to the datatable } } catch {} *** the problem is it never goes to the WHILE loop, and i don't what the line above it causes the error. Anyone has any idea, please help. :( *HyVong*

          H Offline
          H Offline
          HyVong
          wrote on last edited by
          #4

          actually, i found the error :) reader = new System.IO.StreamReader(fs); :-D *HyVong*

          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