Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 834
joshua Avatar asked May 01 '26 16:05

joshua


1 Answers

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);
like image 169
Adam Rackis Avatar answered May 03 '26 07:05

Adam Rackis