Solved

checking for dbnull values - sqldatareader ordinals

Posted on 2007-12-04
4
1,444 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
[X]
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
  • 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

695 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