简体   繁体   中英

Can I pass a DBNull to Integer type variable?

Is this possible to send a DB null to a integer variable.

I'm calling a function

private void BindGridView(String Fromdate, String Todate, int IsPending)
  1. fromdate
  2. todate
  3. ispending is my stored procedure scalar variable

On pageload I show the both detail (ispending or not pending). For this I need to pass null.

Is there need to change the signature of function?

Make the int parameter nullable, then check for a value when calling your sproc:

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

and then

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

Try a Nullable Type. In C# you can use the question mark. Instead of Nullable<int> you can write int ?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM