I have created a small table in SQL Server CE 3.5
Following is the table description:
ROW_ID NVARCHAR(30),
NAME NVARCHAR(30),
TEST BIT
I am using following query to insert record in the table:
insert into EMP(ROW_ID, NAME, TEST)
values('123', 'XYZ', TRUE);
But I am getting a strange error:
Error Message: The column name is not valid. [Node Name (if any) = ,Column name = TRUE]
Please help me with this.
Thanks in advance.
To insert a new value to the BIT column, use INSERT statement: INSERT INTO table_name (bit_column) VALUES (1); You can also use TRUE and FALSE as the inputs for the BIT columns, SQL Server will automatically convert them as follow: TRUE will be converted to 1.
Bit values can be inserted with b'value' notation, where value is the bit value in 0's and 1's. Bit fields are automatically zero-padded from the left to the full length of the bit, so for example in a BIT(4) field, '10' is equivalent to '0010'.
The BIT data type is an integer value that accepts 0, 1, and NULL. BIT represents a boolean type with TRUE (1) and FALSE (0) values. String values 'TRUE' and 'FALSE' are also accepted and converted to 1 and 0.
Instead of true
and false
use 1
and 0
. Eg:
insert into EMP(ROW_ID, NAME, TEST)
values('123','XYZ',1);
This is for SQL Server 2005 bit
:
The string values TRUE and FALSE can be converted to bit values: TRUE is converted to 1 and FALSE is converted to 0.
You can try it. If it applies to CE following code ('TRUE'
as string) might work as well:
insert into EMP(ROW_ID, NAME, TEST)
values('123','XYZ', 'TRUE');
Nothing strange about that. It's saying is doesn't know what TRUE is. Not a known name, not a column in the table, hence error message.
Use 1 for true, 0 for false.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With