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