我正在尝试将大量 excel 插入到 sql
sqlBulk.WriteToServer(dReader);
给出错误
来自数据源的 String 类型的给定值无法转换为指定目标列的 float 类型。
我正在使用下面的代码
System.Data.SqlClient.SqlConnection strConnection;
strConnection = new System.Data.SqlClient.SqlConnection("Data Source=L06DPSGCD0001;Initial Catalog=ProductionEfficiency;User ID=sample;Password=sample");
string path = ("C:\\Users\\s3802616\\Desktop\\" + (FileUpload1.FileName));
System.Diagnostics.Debug.WriteLine("C:\\Users\\s3802616\\Desktop\\" + (FileUpload1.FileName));
string excelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=" + "\"" + "Excel 12.0;HDR=YES;" + "\"";
//Create Connection to Excel work book
OleDbConnection excelConnection = new OleDbConnection(excelConnectionString);
//Create OleDbCommand to fetch data from Excel
OleDbCommand cmd = new OleDbCommand("Select [Model],[Process],[STD_Hours],[UOM],[Section] from [Sheet1$]", excelConnection);
//OleDbCommand cmd = new OleDbCommand("Select * from [Sheet1$]", excelConnection);
excelConnection.Open();
strConnection.Open();
OleDbDataReader dReader;
dReader = cmd.ExecuteReader();
SqlBulkCopy sqlBulk = new SqlBulkCopy(strConnection);
//Give your Destination table name
sqlBulk.DestinationTableName = "dbo.tblProcessStdHours";
sqlBulk.WriteToServer(dReader);
excelConnection.Close();
strConnection.Close();
lblStatus.Text = "Uploaded Successfully";
请建议。