Click here to Skip to main content
11,577,710 members (62,131 online)
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)

  Print Answers RSS
0 Peter Leow 180
1 Richard MacCutchan 175
2 DamithSL 150
3 OriginalGriff 135
4 Afzaal Ahmad Zeeshan 95
0 OriginalGriff 830
1 Sergey Alexandrovich Kryukov 701
2 Abhinav S 573
3 F-ES Sitecore 420
4 Dave Kreskowiak 374


Advertise | Privacy | Mobile
Web04 | 2.8.150603.1 | Last Updated 21 May 2012
Copyright © CodeProject, 1999-2015
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