Sending stored proc Parameter

  • Thread starter Thread starter Rob
  • Start date Start date
R

Rob

What is the syntax to send a null value as a parameter ?

cmd.Parameters.Add("@Year", Convert.ToInt32(strYear))

in cases where strYear = ""

I want to send ...

cmd.Parameters.Add("@Year", Null)

But the syntax is incorrect....

How would I send it ?
 
What is the syntax to send a null value as a parameter ?

cmd.Parameters.Add("@Year", Convert.ToInt32(strYear))

in cases where strYear = ""

I want to send ...

cmd.Parameters.Add("@Year", Null)

But the syntax is incorrect....

How would I send it ?

Will it accept DbNull?

Thanks,

Seth Rowe
 
Rob said:
What is the syntax to send a null value as a parameter ?

cmd.Parameters.Add("@Year", Convert.ToInt32(strYear))

in cases where strYear = ""

I want to send ...

cmd.Parameters.Add("@Year", Null)

But the syntax is incorrect....

How would I send it ?

'untested, without string validation:
shared function ABC(byval s as string) as object

if s.length=0 then return dbnull.value
return cint(s)

end function

cmd.Parameters.Add("@Year", ABC(strYear))


Armin
 
Rob said:
What is the syntax to send a null value as a parameter ?

cmd.Parameters.Add("@Year", Convert.ToInt32(strYear))

in cases where strYear = ""

I want to send ...

cmd.Parameters.Add("@Year", Null)

But the syntax is incorrect....

How would I send it ?

You create a parameter with the correct type and set the value to DBNull:

cmd.Parameters.Add("@Year", SqlDbType.Int).Value = DBNull.Value
 
Hi Rob,

Did you try DbNull.Value ?

Regards,
Bill.






- Show quoted text -

Thats what I meant - do I get partial credit for saying DbNull?

:-)

Thanks,

Seth Rowe
 
Hi Seth,

Sure do :) For some reason I always look for DbNull.Default only to realize
it's DbNull.Value I need.
 
Back
Top