我可以将DBNull传递给Integer类型变量吗?

jos*_*hua 3 c# asp.net stored-procedures sql-server-2008

是否可以将DB null发送到整数变量.

我正在调用一个函数

private void BindGridView(String Fromdate, String Todate, int IsPending)
Run Code Online (Sandbox Code Playgroud)
  1. 从日期
  2. 至今
  3. ispending 是我的存储过程标量变量

在页面加载中,我显示了两个细节(正在等待或未挂起).为此,我需要传递null.

是否需要更改功能的签名?

Ada*_*kis 6

使int参数可为空,然后在调用sproc时检查一个值:

private void BindGridView(String Fromdate, String Todate, int? IsPending) {
Run Code Online (Sandbox Code Playgroud)

然后

cmd.Parameters.AddWithValue("@intParam", 
                 IsPending.HasValue ? (object)IsPending.Value : DBNull.Value);
Run Code Online (Sandbox Code Playgroud)