Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I am using SqlCommand to insert or update values in a row of a table. I have added the parameters in the sqlcommand object. I want to update some of the column values to null. How can I update a cell with the value as NULL.

Thanks,
Velkumar
Posted
Comments
Zoltán Zörgő 27-May-12 13:38pm    
Any progress?

Try this

Method1:
C#
SqlCommand command = new SqlCommand("insert into TableName values
            (@Col1,@Col2)",connection);
command.Parameters.AddWithValue("@Col2",DBNull.Value);


Method2:
C#
SqlCommand command = new SqlCommand("insert into TableName values
            (@Col1,@Col2)",connection);
command.Parameters.Add("@Col2",System.Data.SqlDbType.Int).Value=DBNull.Value;
 
Share this answer
 
v2
Comments
Velkumar Kannan 21-May-12 6:44am    
Thanks. Its works fine.
 
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