Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# SQL SQL-Server Parameter insert , +
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 20-May-12 23:09pm
Comments
Zoltán Zörgő at 27-May-12 13:38pm
   
Any progress?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Try this
 
Method1:
SqlCommand command = new SqlCommand("insert into TableName values
            (@Col1,@Col2)",connection);
command.Parameters.AddWithValue("@Col2",DBNull.Value);
 
Method2:
SqlCommand command = new SqlCommand("insert into TableName values
            (@Col1,@Col2)",connection);
command.Parameters.Add("@Col2",System.Data.SqlDbType.Int).Value=DBNull.Value;
  Permalink  
v2
Comments
Velkumar Kannan at 21-May-12 6:44am
   
Thanks. Its works fine.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  

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



Advertise | Privacy | Mobile
Web01 | 2.8.140926.1 | Last Updated 21 May 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100