Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ternary statement and nulls

Status
Not open for further replies.

tshad

Programmer
Jul 15, 2004
386
0
0
US
I want to be able to do a conditional with both null and int.

Code:
database.SetParameter("@UserID", SqlDbType.Int, companyID == null? DBNull.Value : companyID),

I have many overloads for SetParameter. One has the last parameter as integer and on that has it as DBNull.

Both work fine individually but if I use a conditional, I can't because the types are different and there is no implicit conversion.

One result was to cast one of the sides to (object). But then it would pick the right overload. Is there a way to do this?

Thanks,

Tom
 
If companyID is an int it can never be null as its a value type.

Rhys

"Technological progress is like an axe in the hands of a pathological criminal"
"Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe"
Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top