且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用C#的SqlCommand参数在Sql Server2008中插入空值.

更新时间:2023-01-22 17:15:03

尝试一下

方法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://***.com/questions/4555935/how-to-assign-null-to-a-sqlparameter[^]