ExecuteScalar

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

    ExecuteScalar

    Hello All, what is the correct / proper way to check for null values in the
    ExecuteScalar. System.DBNull.V alue, Null or both?

  • =?Utf-8?B?TWlzYmFoIEFyZWZpbg==?=

    #2
    RE: ExecuteScalar

    it really depends on what you need to find out about the result
    if you need to test if a the row/data exists then just check for null and
    you need to test if the row/data exists and has a valid value then try the
    following

    ///
    object result = cmd.ExecuteScal ar();

    if (result == null)
    return "Customer not found";
    if (result == System.DBNull.V alue)
    return "Customer found but name is null";
    return (string) result;
    ///


    --
    Misbah Arefin




    "MDB" wrote:
    Hello All, what is the correct / proper way to check for null values in the
    ExecuteScalar. System.DBNull.V alue, Null or both?
    >
    >

    Comment

    • MDB

      #3
      Re: ExecuteScalar

      Okay, I am not thinking straight this morning and understand now. Thanks.

      "Misbah Arefin" <MisbahArefin@d iscussions.micr osoft.comwrote in message
      news:F1D650E9-18EF-4033-9C4B-4009547F20EB@mi crosoft.com...
      it really depends on what you need to find out about the result
      if you need to test if a the row/data exists then just check for null and
      you need to test if the row/data exists and has a valid value then try the
      following
      >
      ///
      object result = cmd.ExecuteScal ar();
      >
      if (result == null)
      return "Customer not found";
      if (result == System.DBNull.V alue)
      return "Customer found but name is null";
      return (string) result;
      ///
      >
      >
      --
      Misbah Arefin


      >
      >
      "MDB" wrote:
      >
      >Hello All, what is the correct / proper way to check for null values in
      >the
      >ExecuteScala r. System.DBNull.V alue, Null or both?
      >>
      >>

      Comment

      Working...