I have a bunch of Yes/No fields in Access database that I need to get into SQL Server. If I look at the Access data, those fields contain either 0 or -1. On SQL Server side I created fields of type BIT which did not work for me, I am assuming because BIT expects 0 or 1. Here is my error:
The given value of type String from the data source cannot be converted to type bit of the specified target column. --->
System.FormatException: Failed to convert parameter value from a String to a Boolean.
String was not recognized as a valid Boolean
I also tried using nvarchar(3) which also did not work, saying "The given value of type String from the data source cannot be converted to type nvarchar"
Which data type should I use? I have tried BIT, TINYINT, NVARCHAR(3), CHAR(1), and CHAR(2).
Using CHAR(1) or CHAR(2) gives me a different error:
System.Data.SqlClient.SqlException (0x80131904): Received an invalid column length from the bcp client for colid 13.
But either way nothing works
I always use SMALLINT
(2-byte signed integer) to allow for 0 and -1, and avoid the hassle with BIT fields.
Use a bit, and you'll want to do a transform from Yes to 1 and No to 0 during the import, you can use a CASE statement to handle this operation.
IE
CASE WHEN colVal = 'Yes' THEN 1 ELSE 0
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.