PC Review


Reply
Thread Tools Rate Thread

how to detect if column in IDataReader has a NULL value?

 
 
Jeff
Guest
Posts: n/a
 
      26th Oct 2008
hi

..net 2.0

IDataReader reader;
if (reader["field1"] == null)
{
}

This if test don't come true. I've just tested it with a NULL value in
field1, and the code block within the if statement wasn't executed. Instead
it executed the else block (not shown here.)

any suggestions?


 
Reply With Quote
 
 
 
 
sloan
Guest
Posts: n/a
 
      26th Oct 2008
IDataReader idr;


if (!(idr.IsDBNull(0)))
{
myObject.MyGuid = idr.GetGuid(0);
}




"Jeff" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> hi
>
> .net 2.0
>
> IDataReader reader;
> if (reader["field1"] == null)
> {
> }
>
> This if test don't come true. I've just tested it with a NULL value in
> field1, and the code block within the if statement wasn't executed.
> Instead it executed the else block (not shown here.)
>
> any suggestions?
>



 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      26th Oct 2008
Jeff wrote:

> IDataReader reader;
> if (reader["field1"] == null)


if (System.DBNull.Value.Equals(reader["field1"]))


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert query with null column and null value =?Utf-8?B?RXVnZW5l?= Microsoft Access Queries 10 5th Oct 2007 03:41 AM
How to detect a null value keithb Microsoft C# .NET 4 20th Mar 2006 01:34 PM
Detect NULL (??) range? Ed Microsoft Excel Programming 4 25th Jan 2005 04:14 PM
Is IDataReader.GetInt32 more efficient than IDataReader.Item? Rob Nicholson Microsoft ADO .NET 9 6th May 2004 02:18 AM
Detect a NULL string John Smith Microsoft ASP .NET 5 1st Dec 2003 08:52 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:43 AM.