Click here to Skip to main content
16,020,669 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am tring to read data from CSV file and and insert the data into multiple tables.
I am having trouble inserting data into the tables.
could some one help me.

Thanks
Posted
Comments
Nelek 12-Nov-12 15:17pm    
Orcun Iyigun 12-Nov-12 17:08pm    
I love this link. added to my favourites :)
Sergey Alexandrovich Kryukov 12-Nov-12 16:29pm    
"I am having trouble" is not informative. What's the problem? Any code sample?
--SA
ZurdoDev 12-Nov-12 16:37pm    
Where are you stuck at? What do you have so far? There are a million ways to do this but it will depend on what you have, what your table names are, what your variable names are, etc, etc.

1 solution

Use below code:
C#
OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "CSV document(*.csv)|*.csv";
DialogResult result = dialog.ShowDialog();
if (result == DialogResult.OK)
{
    string csvFile = dialog.FileName;
    Workbook workbook = new Workbook();
    workbook.LoadFromFile(@"..\csvtodatatable.csv", ",");
    Worksheet worksheet = workbook.Worksheets[0];
    System.Data.DataTable t = worksheet.ExportDataTable();
    this.dataGridView1.DataSource = t;


Details can be seen:CSV to Datatable C#[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900