使用C#将数据从excel导出到sql [英] export datas from excel to sql using c#

查看:71
本文介绍了使用C#将数据从excel导出到sql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用c#将数据从excel导出到sql:
如果它只有1个表,我可以将Excel中的选项卡导出到sql.dnt knw hw 2导出具有多个具有相同列的表的选项卡.也我不知道2如何使用字段名称,即A1:BE12,A3,C5等在c#编码中将其用于导出到sql.如果要从excel导出,也请联系我如何在sql中创建表.如果您知道,请帮助我...

Export datas from excel to sql using c#:
I could export a tab in excel to sql if it has only 1 table.dnt knw hw 2 export a tab having multiple tables with some same columns.also i dnt knw how 2 use the field names i.e A1:BE12,A3,C5 etc in the c# codings to use it for export to sql.Also tel me how to create tables in sql if we want to export as it is from excel.If u knw,help me...

推荐答案

要从excel导出,请编写如下代码

To export as it is from excel, code something like this

SqlCommand cmd = null; // create the command with open connection here
string table_name = "newTableName";
string sql = "select * into "+  table_name + " FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0;Database=\\shareddrive\testing.xlsx;HDR=YES', 'SELECT * FROM [SheetName


')"; cmd.ExecuteNonQuery(sql);
')"; cmd.ExecuteNonQuery(sql);


这篇关于使用C#将数据从excel导出到sql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆