Click here to Skip to main content
15,902,635 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends,

I want to dump some bulk data from tab delimited text file to database table using SQLBulkcopy.

Here my issue is my database tables are having columns with datatype as nvarchar whereas my datatable defined with columns datatype as String which throws an exception as follows:
C#
The given value of type String from the data source cannot be converted to type nvarchar of the specified target column.


Please suggest me how to define a column datatype as nvarchar rather than string for a datatable.
C#
dtData.Columns.Add("RegionCode", typeof(string));


or please suggest me any alternative.

Thank You..
Posted
v2

1 solution

c# can't insert data table using sqlbulkcopy[^].
Quote:
It may be caused by a too-short-column. If your ShortText column is defined as NVARCHAR(30) and you have a 40 character string, you may get that error. See here for example:
http://forums.asp.net/p/1228890/2212376.aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900