Link to home
Start Free TrialLog in
Avatar of MrAgile
MrAgileFlag for Australia

asked on

checking for dbnull values - sqldatareader ordinals

Hi There,

What's the syntax for testing for sqldatareader ordinals for null?I tried something like below but it's not working.

Sean


           class.propertyname = reader.GetOrdinal("myID")== DBNull.Value ? 0 : reader.GetInt32(reader.GetOrdinal("myID"));



ASKER CERTIFIED SOLUTION
Avatar of sognoct
sognoct
Flag of Italy image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sounds like what you really want to do is have a COALESCE statement in the sql used to create the reader, to that a NULL value is never returned in the first place.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MrAgile

ASKER

hi jcoehoorn,

I have done this already. I am just making sure that there is no way this thing is going to fall over in a nasty way.