Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 将多行传递给SQL Server存储过程_Excel_Sql Server 2008_Stored Procedures_Import_C# 2.0 - Fatal编程技术网

Excel 将多行传递给SQL Server存储过程

Excel 将多行传递给SQL Server存储过程,excel,sql-server-2008,stored-procedures,import,c#-2.0,Excel,Sql Server 2008,Stored Procedures,Import,C# 2.0,我有一个问题,我想将多行Excel文件传递给SQL Server存储过程,但我对此一无所知。 我有一个Excel文件要导入,数据需要插入到三个不同的表中。我已成功地将数据导入到一个表中,如下所示 string path = string.Concat((Server.MapPath("~/temp/"+FileUpload1.FileName))); FileUpload1.PostedFile.SaveAs(path); OleDbConnection oleCon = new OleDbCo

我有一个问题,我想将多行Excel文件传递给SQL Server
存储过程,但我对此一无所知。
我有一个Excel文件要导入,数据需要插入到三个不同的表中。我已成功地将数据导入到一个表中,如下所示

string path = string.Concat((Server.MapPath("~/temp/"+FileUpload1.FileName)));
FileUpload1.PostedFile.SaveAs(path);
OleDbConnection oleCon = new OleDbConnection("Provider=Microsoft.Ace.OLEDB.12.0;Data Source=" + path + ";Extended Properties = Excel 12.0;");
OleDbCommand cmd = new OleDbCommand("select * from [Sheet1$]",oleCon);
OleDbDataAdapter dtap = new OleDbDataAdapter(cmd);
oleCon.Open();
DbDataReader rdr = cmd.ExecuteReader();
string con_str = @"Data source = .;Initial Catalog=practiceDB;Integrated security=True";
SqlBulkCopy bulkInsert = new SqlBulkCopy(con_str);
bulkInsert.DestinationTableName = "Excel_New";
bulkInsert.WriteToServer(rdr);
oleCon.Close();
Array.ForEach(Directory.GetFiles((Server.MapPath("~/temp/"))),File.Delete);

如何将行发送到存储过程而不是任何
DestinationTable

而不是将行作为参数传递,只从存储过程中的表
Excel\u New
中读取行如何?

如果您确实不想使用存储过程,则有一种可能的方法(可能是长过程),将excel数据转换为XML,然后将此XML作为参数传递给存储过程。最后,从XML读取到临时表,并插入到相应的表中。