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

本文关键字:类型变量 Integer DBNull 我可以 | 更新日期: 2023-09-27 18:17:05

是否可以将DB null发送给整数变量?

我正在调用一个函数

private void BindGridView(String Fromdate, String Todate, int IsPending)
  1. fromdate
  2. 迄今为止,
  3. 开销是我的存储过程标量变量

在页面加载时,我显示了这两个细节(花费或不挂起)。为此,我需要传递null。

是否需要更改函数的签名?

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

使int形参可为空,然后在调用您的程序时检查是否有值:

private void BindGridView(String Fromdate, String Todate, int? IsPending) {

cmd.Parameters.AddWithValue("@intParam", 
                 IsPending.HasValue ? (object)IsPending.Value : DBNull.Value);

尝试一个可空类型。在c#中,你可以使用问号。而不是Nullable你可以写int ?

private void BindGridView(String Fromdate, String Todate, int ? IsPending)