Google Answers Logo
View Question
 
Q: SqlDataReader.IsDBNull Method ( Answered 5 out of 5 stars,   0 Comments )
Question  
Subject: SqlDataReader.IsDBNull Method
Category: Computers > Programming
Asked by: homebuilder-ga
List Price: $10.00
Posted: 20 Feb 2003 09:12 PST
Expires: 22 Mar 2003 09:12 PST
Question ID: 163956
SqlDataReader.IsDBNull Method 
I think i need to use this to check for null values prior to using the
statement "address.Value = myReader.GetString(5)" otherwise I get the
error "Data is Null. This method or property cannot be called on Null
values"
but am unsure of the code to use it.Please could you give me an
example of the required code to check for null values prior to using
the getstring method
Thanks

Request for Question Clarification by bio-ga on 20 Feb 2003 11:22 PST
Hi,

Can you please clarify what language and what database server are you using?

Thanks
Bio

Clarification of Question by homebuilder-ga on 20 Feb 2003 12:31 PST
I am using VB.Net with SQL Server2000 running on Windows 2000 Server.
Answer  
Subject: Re: SqlDataReader.IsDBNull Method
Answered By: cerebrate-ga on 21 Feb 2003 23:10 PST
Rated:5 out of 5 stars
 
Dear homebuilder-ga,

You're quite correct in that you need to call this method in order to
check for NULL values before retrieving data through your
SqlDataReader. The specific code you need to do this looks like this:

If (myReader.IsDBNull (5)) Then
  ' Handle a NULL value, in some appropriate way. Here, I just
substitute
  ' an empty string for the NULL.
  address.Value = ""
Else
  ' Retrieve the actual value
  address.Value = myReader.GetString (5)
End If

An example of using a SqlDataReader to read information from a
database, including this code, can be found by going to:

http://samples.gotdotnet.com/quickstart/howto/

then scrolling down to "Data and ADO.NET", and selecting "Retrieve
data from a SQLServer database".

If this answer isn't quite what you're looking for, please feel free
to request a clarification,

cerebrate-ga

Search strategy:

Personal knowledge.
homebuilder-ga rated this answer:5 out of 5 stars

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy