Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
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 12-Nov-12 10:16am
Comments
Nelek at 12-Nov-12 15:17pm
   
Orcun Iyigun at 12-Nov-12 17:08pm
   
I love this link. added to my favourites :)
Sergey Alexandrovich Kryukov at 12-Nov-12 16:29pm
   
"I am having trouble" is not informative. What's the problem? Any code sample?
--SA
ryanb31 at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Use below code:
            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#[^]
  Permalink  

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



Advertise | Privacy | Mobile
Web04 | 2.8.150302.1 | Last Updated 13 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100