Sqlbulkcopy浮动转换错误(asp.net c#)

Iam试图插入大量的Excel到SQL

sqlBulk.WriteToServer(dReader); 给出错误

来自数据源的Stringtypes的给定值不能转换为指定目标列的floattypes。

Iam使用下面的代码

  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"; 

请build议。

错误说明了一切。

您正在尝试复制“float”types的目标列中的“string/字符”。

您需要将数据库表“dbo.tblProcessStdHours”中的目标列的数据types更改为varchar。