Solved

checking for dbnull values - sqldatareader ordinals

Posted on 2007-12-04
4
1,439 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

912 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now