2
執行批量複製時出現以下錯誤。System.InvalidOperationException和SQlBulkCopy
System.InvalidOperationException
The given value of type String from the data source cannot be converted to
type decimal of the specified target column.
我使用下面的代碼。
DataTable empTable = DataTemplate.GetEmployees();
DataRow row;
for (int i = 0; i < gv.Rows.Count;i++)
{
row = empTable.NewRow();
string empName = gv.DataKeys[i].Values[0].ToString(); //first key
string hourSalary = gv.DataKeys[i].Values[1].ToString(); //second key
row["Emp_Name"] = empName;
row["Hour_Salary"] = Convert.ToDecimal(hourSalary);
row["Advance_amount"] = Convert.ToDecimal(0);
row["Created_Date"] = Convert.ToDateTime(System.DateTime.Now.ToString());
row["Created_By"] = Convert.ToInt64(1);
row["Is_Deleted"] = Convert.ToInt64(0);
empTable.Rows.Add(row);
}
InsertintoEmployees(empTable, "Employee");
用於上述領域我的SQL數據類型是:
Emp_Name nvarchar(50) ,
Hour_Salary numeric(18, 2),
Advance_amount numeric(18, 2),
Created_Date datetime,
Created_By numeric(18, 0),
Is_Deleted numeric(18, 0)
我不知道我做錯了。
請包括Exception.ToString()的返回值(包括堆棧跟蹤)想法是知道在填充DataTable時還是在將DataTables內容傳輸到數據庫表時,是否收到異常。 –