Thursday, April 25, 2013

Converting Csv to DataTable

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

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.

Friday, April 19, 2013

Excel Load To DataTable using OleDb in C#

Here we will try to load Excel sheet  data into the datatable using Jet engine.
First, We need to  Download and install the AccessDatabaseEngine exe from the microsoft web site.

Complete Source Code.