1

I'm trying to use SqlBulkCopy to upload a data table into SQL Server.

I'm getting this error:

String or binary data would be truncated.

I'm using

sqlBulkcopy.WriteToServer(dtCustom)

The SQL Server column is defined as nvarchar(50)

I changed the column to nvarchar(150) and same problem

This line is causing the problems with the import:

Enter the Location of Inspection

The line is 32 characters

If I remove "on" then it works and imports.

So what's the deal with a SQL Server table column defined as nvarchar(50) and 32 characters for data going into it?

Any ideas?

3
  • Are your columns in the same order in the source and destination? Commented Feb 24, 2015 at 22:00
  • The data is from an XML file. The columns are in the same order as read in. But the next XmlNode, after this one, is not added to the table at all. The XML is read into a datatable (dtCustom). Then the datatable is copied into the SQL table. Commented Feb 25, 2015 at 16:08
  • I have a similar issue. When you say: if I remove "on" then it works and imports., what does it mean? Commented Jan 26, 2017 at 1:38

1 Answer 1

1

The columns have to be mapped. Even though the datatable has the same column names as the SQL table - in the asp.net vb coding you still have to do column mappings.

Sign up to request clarification or add additional context in comments.

1 Comment

adding the mappings fixed it for me as well.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.