Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

checking for dbnull values - sqldatareader ordinals

Posted on 2007-12-04
4
1,441 Views
Last Modified: 2013-12-16
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"));



0
Comment
Question by:MrAgile
  • 2
4 Comments
 
LVL 9

Accepted Solution

by:
sognoct earned 500 total points
ID: 20401857
try :
class.propertyname =  reader.IsDBNull(reader.GetOrdinal("prova")) ? 0 : reader.GetInt32(reader.GetOrdinal("myID"));
0
 
LVL 18

Expert Comment

by:jcoehoorn
ID: 20403896
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.
0
 
LVL 9

Assisted Solution

by:sognoct
sognoct earned 500 total points
ID: 20403957
class.propertyname =  reader.IsDBNull(reader.GetOrdinal("myID")) ? 0 : reader.GetInt32(reader.GetOrdinal("myID"));
0
 
LVL 8

Author Comment

by:MrAgile
ID: 20406655
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.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question