Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
How we can pass null value for int, decimal datatype in database (sql server) in asp.net C#
Posted

create a parameterized query and try passing 'System.DBNull.Value' to that column.
 
Share this answer
 
v3
Hi Please try this

C#
//ID -> INT - NOT NULL
//SL_NO -> INT ->NULL
//NAME -> NVARCHAR(50)
string yourQuery = string.Format(@"INSERT INTO STUDENTMASTER(ID,SL_NO,NAME)VALUES({0},NULL,'{1}')",1,"name");
 
Share this answer
 
insert into table_Name values(Null,Null.............)
Just pass null text that it.

I have try on sql server 2008R2.
 
Share this answer
 
i think we can declare some string as NULL and v can pass that value to sql server....

string value="NULL";


it ll store in database as like NULL only...

I'm Not sure....
Try like this...
 
Share this answer
 
Comments
Sumit_Kumar_Sinha 6-Dec-12 6:28am    
TotalQty int (in database)...........but data inserting time i m not putting the Qty value...........so i want to put null in database if qty textbox is empty
Deenuji 6-Dec-12 6:33am    
so do tick allow null in datatype declaration in that table....

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