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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jeff

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

    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?


  • sloan

    #2
    Re: how to detect if column in IDataReader has a NULL value?

    IDataReader idr;


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




    "Jeff" <it_consultant1 @hotmail.com.NO SPAMwrote in message
    news:%232EuQt1N JHA.1160@TK2MSF TNGP02.phx.gbl. ..
    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?
    >

    Comment

    • Martin Honnen

      #3
      Re: how to detect if column in IDataReader has a NULL value?

      Jeff wrote:
      IDataReader reader;
      if (reader["field1"] == null)
      if (System.DBNull. Value.Equals(re ader["field1"]))


      --

      Martin Honnen --- MVP XML

      Comment

      Working...