Sqlbulkcopy 在浮点转换时出错 (asp.net c#)
Sqlbulkcopy gives error on float conversion (asp.net c#)
我正在尝试将 excel 的大部分内容插入到 sql
sqlBulk.WriteToServer(dReader);
给出错误
The given value of type String from the data source cannot be
converted to type float of the specified target column.
我正在使用以下代码
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";
请建议。
错误说明了一切。
您正试图在 "float" 类型的目标列中复制 "string/chars"。
您需要将数据库 table "dbo.tblProcessStdHours" 中目标列的数据类型更改为 varchar。
我正在尝试将 excel 的大部分内容插入到 sql
sqlBulk.WriteToServer(dReader);
给出错误
The given value of type String from the data source cannot be converted to type float of the specified target column.
我正在使用以下代码
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";
请建议。
错误说明了一切。
您正试图在 "float" 类型的目标列中复制 "string/chars"。
您需要将数据库 table "dbo.tblProcessStdHours" 中目标列的数据类型更改为 varchar。