Last post May 23, 2017 07:24 AM by Eric Du
May 22, 2017 02:56 PM|ngaisteve1|LINK
I have this error at this line:
Line 298: sqlBulkCopy.WriteToServer(dt);
using (SqlBulkCopy sqlBulkCopy = new SqlBulkCopy(con))
//Set the database table name
sqlBulkCopy.DestinationTableName = "dbo.Invoice";
My question is how do I identify which column is having the problem?
May 22, 2017 04:16 PM|PatriceSc|LINK
I don't think you really have an easy way if this is really the full error message you have.
That said it happens necessarily on a string column which is not mapped to a char/varchar column. So check which columns are in this case to get possible candidates. Beyond solving this immediate problem I would try to see if this kind of late error couldn't
be avoided by having in dt a column type that matches the actual target type on the db site (and so it would happen when dt is loaded).
May 23, 2017 05:48 AM|ngaisteve1|LINK
Put manually map with this code?
the datatable column is field1 while SQL column is myfield1?
May 23, 2017 07:24 AM|Eric Du|LINK
After reading your description, as far as I know, this issue is not the full error message, you could add a breakpoint to check it stop which line code.
Also about Map the DataTable columns with that of the database table:
sqlBulkCopy.ColumnMappings.Add("datatable column","database table column");
For more details, please refer to this tutorial:
SqlBulkCopy: Bulk Copy data from DataTable (DataSet) to SQL Server Table using C# and VB.Net: