Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert NULL value into database

Status
Not open for further replies.

columbo2

Technical User
Jul 14, 2006
97
GB
Hi

I have an update statement and when fields in my form are left blank I want NULL inserted into the databse rather than "".

I can't find a way to do it.

If I can't find another way my plan is to set the fields in the data base to <NULL> using c# then use a second SQL query after the update to update the row and actually make these cells proper SQL null columns.

It seems a really messy way to do it.
Is there some way of setting to Null directly?

thanks
C
 
Actually I think I'll set all of the fields that could be null to null first then, write the new data over the top.
Still a bit messt but better I think
 
how are you issuing this query?

if its' a normal string you just need to pass the string "null" ie:

Code:
string myCommandText = "insert into zeTable (Column1, Column2) values (null, 'realvalue')"

If you are using stored procedures with parameters you'd need to assign their value to DBNull.Value I believe.

Hope this helps,

Alex



[small]----signature below----[/small]
Now you can go where the people are one!
Now you can go where they get things done!
 
what an idiot I am.
You're right

I was stuck on thinking about having to pass the null value through a parameteter and forgetting the odvious.

I'm building the update query any way so, as you say I'll just write it into the statement as SQL.

thanks
ta
C
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top