使用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);