如何将CSV数据插入数据库表 [英] How to insert the CSV data into the database table
本文介绍了如何将CSV数据插入数据库表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正试图从CSV文件读取数据并将数据插入到多个表中.
我在将数据插入表时遇到问题.
有人可以帮我吗.
谢谢
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
推荐答案
使用以下代码:
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;
可以查看详细信息: CSV到Datatable C# [ ^ ]
Details can be seen:CSV to Datatable C#[^]
这篇关于如何将CSV数据插入数据库表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文