?
Solved

c# dataset value how to check if null

Posted on 2007-08-03
5
Medium Priority
?
521 Views
Last Modified: 2013-11-05
I have a dataset which I am trying to validate before saving to a database.

I get an error if I try to evaluate if it is null
                if ((dr.ResultCode == "Fail"))

II tried to check if it is null, but I can't.  How do you do it?
                if (dr.ResultCode.is = DBNull)

0
Comment
Question by:jackjohnson44
  • 2
  • 2
5 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 19625264
if (dr.ResultCode.ToString() == "Fail")

Bob


0
 

Author Comment

by:jackjohnson44
ID: 19625434
Thanks, but how do you check if a value is null?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 19625450
ToString will convert null to an empty string "".  

If you want to check for DBNull, then you need:

  if (dr.ResultCode == DBNull.Value)

Bob
0
 

Author Comment

by:jackjohnson44
ID: 19627844
This does not work, it iwll fail

  if (dr.ResultCode == DBNull.Value)
0
 
LVL 25

Accepted Solution

by:
dstanley9 earned 2000 total points
ID: 19627894
try
if (dr.IsResultCodeNull)
or
if (dr.IsNull("ResultCode"))
0

Featured Post

Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

Question has a verified solution.

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

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

840 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