Steps:
1. First, by using the File class static method ReadAllLines(path), read all the lines from the csv file to the string array.
2. In the resulting array, first element contains the column names. using the first line, we should create the Data table columns.
3. Other than the first element, all other elements contains the row's data. Using the same we can create the data table rows.
Output
TechKindle@Gopi
Learn from yesterday, live for today, hope for tomorrow.
Thursday, April 25, 2013
Creating Csv file from DataTable in C#
Steps:
1. Create a DataTable Schema.
2. Fill the created table with some sample data.
3. Create a StringBuilder, by appending all the data, (using comma delimiter)
a) Create one new line with data table columns.
b) Create one line for each data table row.
4. Save the StringBuilder to Csv file, using FileStream.
1. Create a DataTable Schema.
2. Fill the created table with some sample data.
3. Create a StringBuilder, by appending all the data, (using comma delimiter)
a) Create one new line with data table columns.
b) Create one line for each data table row.
4. Save the StringBuilder to Csv file, using FileStream.
Subscribe to:
Posts (Atom)
