Hi,
I have a general question on CSV import and I am sorry if this has been asked before on this forum.
So, I have a UI page with the data entry fields. I have to implement import functionality by which user can select the csv file and when they load it, the appropriate data entry field should populate the value.
What is the best way ( performance wise) to accomplish this?
Any suggestion is highly appreciated.
Loading
Lacy MichellePosted Oct 25, 2012, 2:40 AM
private void button1_Click(object sender, EventArgs e){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(@"D:\michelle\my file\csvtodatatable.csv", ",");Worksheet worksheet = workbook.Worksheets[0];System.Data.DataTable t = worksheet.ExportDataTable();this.dataGridView1.DataSource = t;}}Then, you can connect it to database. Details can be seen:
CSV to Datatable C#
Lacy MichellePosted Oct 25, 2012, 9:26 PM
Deer ParkPosted Oct 25, 2012, 9:31 AM
Jignesh TrivediPosted Oct 25, 2012, 12:02 AM
for the csv file import, you have anly way read it save it.
but csv fileds are same database filed then i think you can use bulk insert (BCP) utility of SQL server.
or may be you can use third party control like FileHelpers.
hope this will help you.