DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2

Thread: IsDBNull

  1. #1
    Beginner Guest

    IsDBNull


    Let's say I have a SQL database with a table where a particular column allows
    nulls. If I populate a DataSet or DataReader object with data from this table,
    how do I determine if a field I'm reading is set to null? For example, in
    VB.NET, I can use the IsDBNull function:

    If IsDBNull(objDataReader.Item("EMail")) = False Then
    Console.Write("EMail is not null")
    Else
    Console.Write("EMail is null")
    End If

    How do I do this in C#?


  2. #2
    Sergey Kats Guest

    Re: IsDBNull

    C# has the same function:
    if (Convert.IsDBNull(objDataReader.Item("EMail")))

    You can also do the following:
    if (objDataReader.Item("EMail") == DBNull.Value)

    or if (objDataReader.IsDBNull(idx))
    where idx is the column index

    Sergey.

    "Beginner" <a@b.c> wrote in message news:3c042467@147.208.176.211...
    >
    > Let's say I have a SQL database with a table where a particular column

    allows
    > nulls. If I populate a DataSet or DataReader object with data from this

    table,
    > how do I determine if a field I'm reading is set to null? For example, in
    > VB.NET, I can use the IsDBNull function:
    >
    > If IsDBNull(objDataReader.Item("EMail")) = False Then
    > Console.Write("EMail is not null")
    > Else
    > Console.Write("EMail is null")
    > End If
    >
    > How do I do this in C#?
    >




Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links