Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server CE - Unable to insert values in the BIT column

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.

like image 232
Nilesh Barai Avatar asked Jun 16 '13 18:06

Nilesh Barai


People also ask

How do I insert a BIT column in SQL Server?

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.

How do you insert a BIT value?

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'.

What is the BIT value in SQL Server?

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.


2 Answers

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');
like image 89
Michał Powaga Avatar answered Nov 14 '22 22:11

Michał Powaga


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.

like image 4
Tony Hopkinson Avatar answered Nov 14 '22 23:11

Tony Hopkinson