Insert Null Value to SQL Server

  • Thread starter Thread starter Sam
  • Start date Start date
S

Sam

Hi,
I have problem inserting null value through SQLCommand in VB.NET to SQL
Server.

dim cm as new sqlcommand
cm.commandtext = "insert into table1 (field1, field2, ....) values(var1,
var2,....)"

How to assign var2 <== NULL Value, so in SQL Server will appear as null
value ?

thanks,
 
Sam said:
Hi,
I have problem inserting null value through SQLCommand in VB.NET to SQL
Server.

dim cm as new sqlcommand
cm.commandtext = "insert into table1 (field1, field2, ....) values(var1,
var2,....)"

How to assign var2 <== NULL Value, so in SQL Server will appear as null
value ?

Simply do not specify the field:
cm.commandtext = "insert into table1 (field1, field3, ....) values(var1,
var3,....)"

Or, as Jon said, use parameters and set the value to DBNull.Value or to
Nothing (VB.NET) or null (C#)

FB
 
Is there any way i can assign a null value to a Feild in a dataset where the
allow nulls property of that feild is set to false


Manu
 
hmmm .... your question seems to be a bit curious ...
if you have to enter a null value in a field, which does not allow to be
null ... you have to think about your design ....

Regards,
P@rick

PS: I think (hope) there is no way to do this action ... but I'm not sure
....
 
Back
Top