Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a SQL Insert statement that sends data to a SQL Server 2008 table.
The values are picked up from a form using ASP.NET

Sometimes the values will be blank or do not require an answer.
How can I insert these values as NULL into SQL server?
The asp.net form will not save unless I fill in zeros in black fields. But some of the fields in sql server 2008 are “allows null”, but when insert statement is excuted it needs zeros for black fields
Posted

DbNull.Value is how you select null to insert. Or you just use SQL that doesn't have an insert statement for those columns, then they will just stay null.
 
Share this answer
 
Comments
StianSandberg 19-Jul-12 16:32pm    
5'd.
Member 11878307 7-Aug-15 1:14am    
gdgdfdgf
I think if you need to pass string data then use vb.net code like this Dim strValue = string.Empty and for c# string strValue = string.Empty
and you can use DB.Null also for the same
You have one more choice don't pass parameter in sql statement.
Don't pass parameter value in procedure as well, also
Assign null in procedure parameter like @strValue varchar(10)=null

if you will not pass parameter then this will work.

Thanks
Nayan Chavada
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900