Hi I am very new to C# that my first learning curve. My question is How do I read a CSV(Comma Separated Value) file to be processed? Or should I ask what is the best way to process a CSV?
Create a streamreader (TextReader) and read the file line by line. You can then split each line up via commas. As long as your CSV file is formatted correctly you should be able to parse the information out of the file easily after that.
string line = textreader1.ReadLine();
string[] items = line.Split(',');
int ID = Convert.ToInt32(items[0]);
string name = items[1];
...
The other thing you could do is create a DataTable from the Data and as you read each line, dump it into that table. Some people have a DataTable fetish or sorts...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.