使用C#的SqlCommand参数在Sql Server2008中插入空值. [英] Insert null values in Sql Server2008 using SqlCommand parameters of C#.

查看:111
本文介绍了使用C#的SqlCommand参数在Sql Server2008中插入空值.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在使用SqlCommand在表的一行中插入或更新值.我已经在sqlcommand对象中添加了参数.我想将某些列值更新为null.如何更新值为NULL的单元格.

谢谢,
Velkumar

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

推荐答案

尝试一下

方法1:
Try this

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



方法2:



Method2:

SqlCommand command = new SqlCommand("insert into TableName values
            (@Col1,@Col2)",connection);
command.Parameters.Add("@Col2",System.Data.SqlDbType.Int).Value=DBNull.Value;


以下是一些方法:
Here are some methods: http://stackoverflow.com/questions/4555935/how-to-assign-null-to-a-sqlparameter[^]


这篇关于使用C#的SqlCommand参数在Sql Server2008中插入空值.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆