Wednesday, March 28, 2012

How to INSERT DBNull.Values ? ...

Hello,

If I have a database table with column that can accept null values and I want to insert a null value into that column, what is the correct syntax?

db_cmd = New SqlCommand( "sp_stored_procedure", db_connection )
db_cmd.CommandType = CommandType.StoredProcedure
db_cmd.Parameters.Add( "@.col_to_set_to_null", ? )

ie: what expression can be used for "?"

Ideally, I want to check if a string value is empty and if so insert a null, but I have yet to see any examples, ie:

if ( str.empty ) then
insert DBNull.value into column
else
insert str into column
end if

Sincerely,

Brent D.db_cmd.Parameters.Add( "@.col_to_set_to_null", System.DBNull.Value )

No comments:

Post a Comment