websss
asked on
SQL BIT (not Null) - default Value
Hi
I have a .net application that has been runnning fine
I've needed to modify the database to allow for a new column
The new column is called ACTIVE and it's a bit
I want to set it's default Value to true
in the column properties i've added ((1)) against the "Default Value or BInding" property
If i try and add a new record in management studio, it inserts a default value of true
if i try and run it with the application, it says: cannot insert NULL into column active
I really dont want to edit the code and was hoping the database default value would work?
what am i doing wrong?
I have a .net application that has been runnning fine
I've needed to modify the database to allow for a new column
The new column is called ACTIVE and it's a bit
I want to set it's default Value to true
in the column properties i've added ((1)) against the "Default Value or BInding" property
If i try and add a new record in management studio, it inserts a default value of true
if i try and run it with the application, it says: cannot insert NULL into column active
I really dont want to edit the code and was hoping the database default value would work?
what am i doing wrong?
You need to show us the code from your application that is attempting to insert the new record, its the application thats getting it wrong, not the database.
What is the query you are using to insert value ?
IF you want default value to get inserted do not include that field in insert statement.
Means
If you are inserting like this
Insert into tablename ( col1,col2 , ACTIVE) values ( 'a','b',Null)
Do it like this only
Insert into tablename ( col1,col2 ) values ( 'a','b')
IF you want default value to get inserted do not include that field in insert statement.
Means
If you are inserting like this
Insert into tablename ( col1,col2 , ACTIVE) values ( 'a','b',Null)
Do it like this only
Insert into tablename ( col1,col2 ) values ( 'a','b')
ASKER
Hi
I'll dig out the code
BUT
Please note, I said that the .net application was running fine
I then later added a new column in the DB, the code hasn't changed, so it doesn't insert anything for this column
I'll dig out the code
BUT
Please note, I said that the .net application was running fine
I then later added a new column in the DB, the code hasn't changed, so it doesn't insert anything for this column
ASKER
Hi Minhvc
There are lots of contradicting statements on that link.....confusing
There are lots of contradicting statements on that link.....confusing
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Turns out someone altered the code but incorrectly, should have looked there first!