Solved

Checking for null values in date columns coming from SQLSERVER 2000

Posted on 2004-10-19
1
214 Views
Last Modified: 2010-04-23
Hey,  I am retrieving data from sqlServer 2000 with ADO.NET using the dataReader. I have the following statement:
If myReader.IsDBNull(9) = False Then
    UpdateRequest.RenewalDT = myReader.GetDateTime(9).ToShortDateString     'Renewal Date
Else
    UpdateRequest.RenewalDT = String.Empty
End If

I get the following message:
System.Data.SqlTypes.SqlNullValueException: Data is Null. This method or property cannot be called on Null values.

What is the best way to check the datatime column for null values?

Thanks,

Joe
0
Comment
Question by:courchjo
1 Comment
 
LVL 1

Accepted Solution

by:
ndonhauser earned 500 total points
ID: 12349473
If myReader(9) is DBNull.Value Then
    UpdateRequest.RenewalDT = String.Empty
Else
    UpdateRequest.RenewalDT = myReader.GetDateTime(9).ToShortDateString     'Renewal Date
End If

Good Luck.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

680 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