Undefined Value

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

    #1

    Undefined Value


    Hi All,

    What is a best way to handle an undefined value object class that returned
    from a function. I have a function that call the ADO.NET ExecuteScalar()
    function and returns the object to the calling function as follow:


    public object FunctionA()
    {
    object RetVal;
    ... some preparation code here


    RetVal = ExecuteScalar() ; // This one execute a stored procedure
    which can return an empty column

    Return RetVal;
    }


    public int FunctionB()
    {
    object SingleValue;
    ... some code here


    SingleValue = FunctionA();
    }

    The call to the FunctionA works only if the ExecuteScalar() returns a value.
    If the stored procedure returns an empty column value, and then the call to
    the FunctionA() breaks out with an exception...

    Any thoughts????


  • Kevin Yu

    #2
    RE: Undefined Value

    Hi David,

    IDbCommand.Exec uteScalar Method returns the first column of the first row
    in the resultset. If there are no rows returned from your command, a null
    reference is returned. If the first column of the first row is a (Null)
    value, a System.DBNull object is returned. So, if you want to determine if
    any object is returned from the ExecuteScalar() method, you can try the
    following codes:

    command.Connect ion.Open();
    Object o = com.ExecuteScal ar();
    com.Connection. Close();
    if(o != null && o != System.DBNull.V alue)
    return (Int32)o;
    else
    return null;

    Does this answer your question? If anything is unclear, please feel free to
    reply to the post.

    Kevin Yu
    =======
    "This posting is provided "AS IS" with no warranties, and confers no
    rights."

    --------------------
    | From: " David N" <dq.ninh@netiq. com>
    | Subject: Undefined Value
    | Date: Sun, 5 Oct 2003 15:40:25 -0700
    | Lines: 37
    | X-Priority: 3
    | X-MSMail-Priority: Normal
    | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
    | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
    | Message-ID: <OWxJsG5iDHA.11 32@tk2msftngp13 .phx.gbl>
    | Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
    | NNTP-Posting-Host: pat-50.bel.netiq.co m 65.219.170.50
    | Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!tk2 msftngp13.phx.g bl
    | Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:1891 08
    | X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
    |
    |
    | Hi All,
    |
    | What is a best way to handle an undefined value object class that returned
    | from a function. I have a function that call the ADO.NET ExecuteScalar()
    | function and returns the object to the calling function as follow:
    |
    |
    | public object FunctionA()
    | {
    | object RetVal;
    | ... some preparation code here
    |
    |
    | RetVal = ExecuteScalar() ; // This one execute a stored procedure
    | which can return an empty column
    |
    | Return RetVal;
    | }
    |
    |
    | public int FunctionB()
    | {
    | object SingleValue;
    | ... some code here
    |
    |
    | SingleValue = FunctionA();
    | }
    |
    | The call to the FunctionA works only if the ExecuteScalar() returns a
    value.
    | If the stored procedure returns an empty column value, and then the call
    to
    | the FunctionA() breaks out with an exception...
    |
    | Any thoughts????
    |
    |
    |

    Comment

    • Kevin Yu

      #3
      RE: Undefined Value

      Hi David,

      IDbCommand.Exec uteScalar Method returns the first column of the first row
      in the resultset. If there are no rows returned from your command, a null
      reference is returned. If the first column of the first row is a (Null)
      value, a System.DBNull object is returned. So, if you want to determine if
      any object is returned from the ExecuteScalar() method, you can try the
      following codes:

      command.Connect ion.Open();
      Object o = com.ExecuteScal ar();
      com.Connection. Close();
      if(o != null && o != System.DBNull.V alue)
      return (Int32)o;
      else
      return null;

      Does this answer your question? If anything is unclear, please feel free to
      reply to the post.

      Kevin Yu
      =======
      "This posting is provided "AS IS" with no warranties, and confers no
      rights."

      --------------------
      | From: " David N" <dq.ninh@netiq. com>
      | Subject: Undefined Value
      | Date: Sun, 5 Oct 2003 15:40:25 -0700
      | Lines: 37
      | X-Priority: 3
      | X-MSMail-Priority: Normal
      | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
      | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
      | Message-ID: <OWxJsG5iDHA.11 32@tk2msftngp13 .phx.gbl>
      | Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
      | NNTP-Posting-Host: pat-50.bel.netiq.co m 65.219.170.50
      | Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!tk2 msftngp13.phx.g bl
      | Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:1891 08
      | X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
      |
      |
      | Hi All,
      |
      | What is a best way to handle an undefined value object class that returned
      | from a function. I have a function that call the ADO.NET ExecuteScalar()
      | function and returns the object to the calling function as follow:
      |
      |
      | public object FunctionA()
      | {
      | object RetVal;
      | ... some preparation code here
      |
      |
      | RetVal = ExecuteScalar() ; // This one execute a stored procedure
      | which can return an empty column
      |
      | Return RetVal;
      | }
      |
      |
      | public int FunctionB()
      | {
      | object SingleValue;
      | ... some code here
      |
      |
      | SingleValue = FunctionA();
      | }
      |
      | The call to the FunctionA works only if the ExecuteScalar() returns a
      value.
      | If the stored procedure returns an empty column value, and then the call
      to
      | the FunctionA() breaks out with an exception...
      |
      | Any thoughts????
      |
      |
      |

      Comment

      • Kevin Yu

        #4
        RE: Undefined Value

        Hi David,

        I'm sorry that I made a mistake in my former post. If the return value of
        the function is a Int32 type. We cannot use

        else
        return null;

        Because Int32 is a value ype.

        Sorry for my mistake.

        Kevin Yu
        =======
        "This posting is provided "AS IS" with no warranties, and confers no
        rights."

        --------------------
        | X-Tomcat-ID: 46502818
        | References: <OWxJsG5iDHA.11 32@tk2msftngp13 .phx.gbl>
        | MIME-Version: 1.0
        | Content-Type: text/plain
        | Content-Transfer-Encoding: 7bit
        | From: v-kevy@online.mic rosoft.com (Kevin Yu)
        | Organization: Microsoft
        | Date: Mon, 06 Oct 2003 02:47:42 GMT
        | Subject: RE: Undefined Value
        | X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
        | Message-ID: <6CnP6Q7iDHA.68 8@cpmsftngxa06. phx.gbl>
        | Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
        | Lines: 60
        | Path: cpmsftngxa06.ph x.gbl
        | Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:1891 32
        | NNTP-Posting-Host: TOMCATIMPORT1 10.201.218.122
        |
        | Hi David,
        |
        | IDbCommand.Exec uteScalar Method returns the first column of the first row
        | in the resultset. If there are no rows returned from your command, a null
        | reference is returned. If the first column of the first row is a (Null)
        | value, a System.DBNull object is returned. So, if you want to determine
        if
        | any object is returned from the ExecuteScalar() method, you can try the
        | following codes:
        |
        | command.Connect ion.Open();
        | Object o = com.ExecuteScal ar();
        | com.Connection. Close();
        | if(o != null && o != System.DBNull.V alue)
        | return (Int32)o;
        | else
        | return null;
        |
        | Does this answer your question? If anything is unclear, please feel free
        to
        | reply to the post.
        |
        | Kevin Yu
        | =======
        | "This posting is provided "AS IS" with no warranties, and confers no
        | rights."
        |
        | --------------------
        | | From: " David N" <dq.ninh@netiq. com>
        | | Subject: Undefined Value
        | | Date: Sun, 5 Oct 2003 15:40:25 -0700
        | | Lines: 37
        | | X-Priority: 3
        | | X-MSMail-Priority: Normal
        | | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
        | | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
        | | Message-ID: <OWxJsG5iDHA.11 32@tk2msftngp13 .phx.gbl>
        | | Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
        | | NNTP-Posting-Host: pat-50.bel.netiq.co m 65.219.170.50
        | | Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!tk2 msftngp13.phx.g bl
        | | Xref: cpmsftngxa06.ph x.gbl
        microsoft.publi c.dotnet.langua ges.csharp:1891 08
        | | X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
        | |
        | |
        | | Hi All,
        | |
        | | What is a best way to handle an undefined value object class that
        returned
        | | from a function. I have a function that call the ADO.NET
        ExecuteScalar()
        | | function and returns the object to the calling function as follow:
        | |
        | |
        | | public object FunctionA()
        | | {
        | | object RetVal;
        | | ... some preparation code here
        | |
        | |
        | | RetVal = ExecuteScalar() ; // This one execute a stored procedure
        | | which can return an empty column
        | |
        | | Return RetVal;
        | | }
        | |
        | |
        | | public int FunctionB()
        | | {
        | | object SingleValue;
        | | ... some code here
        | |
        | |
        | | SingleValue = FunctionA();
        | | }
        | |
        | | The call to the FunctionA works only if the ExecuteScalar() returns a
        | value.
        | | If the stored procedure returns an empty column value, and then the
        call
        | to
        | | the FunctionA() breaks out with an exception...
        | |
        | | Any thoughts????
        | |
        | |
        | |
        |
        |

        Comment

        • Kevin Yu

          #5
          RE: Undefined Value

          Hi David,

          I'm sorry that I made a mistake in my former post. If the return value of
          the function is a Int32 type. We cannot use

          else
          return null;

          Because Int32 is a value ype.

          Sorry for my mistake.

          Kevin Yu
          =======
          "This posting is provided "AS IS" with no warranties, and confers no
          rights."

          --------------------
          | X-Tomcat-ID: 46502818
          | References: <OWxJsG5iDHA.11 32@tk2msftngp13 .phx.gbl>
          | MIME-Version: 1.0
          | Content-Type: text/plain
          | Content-Transfer-Encoding: 7bit
          | From: v-kevy@online.mic rosoft.com (Kevin Yu)
          | Organization: Microsoft
          | Date: Mon, 06 Oct 2003 02:47:42 GMT
          | Subject: RE: Undefined Value
          | X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
          | Message-ID: <6CnP6Q7iDHA.68 8@cpmsftngxa06. phx.gbl>
          | Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
          | Lines: 60
          | Path: cpmsftngxa06.ph x.gbl
          | Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:1891 32
          | NNTP-Posting-Host: TOMCATIMPORT1 10.201.218.122
          |
          | Hi David,
          |
          | IDbCommand.Exec uteScalar Method returns the first column of the first row
          | in the resultset. If there are no rows returned from your command, a null
          | reference is returned. If the first column of the first row is a (Null)
          | value, a System.DBNull object is returned. So, if you want to determine
          if
          | any object is returned from the ExecuteScalar() method, you can try the
          | following codes:
          |
          | command.Connect ion.Open();
          | Object o = com.ExecuteScal ar();
          | com.Connection. Close();
          | if(o != null && o != System.DBNull.V alue)
          | return (Int32)o;
          | else
          | return null;
          |
          | Does this answer your question? If anything is unclear, please feel free
          to
          | reply to the post.
          |
          | Kevin Yu
          | =======
          | "This posting is provided "AS IS" with no warranties, and confers no
          | rights."
          |
          | --------------------
          | | From: " David N" <dq.ninh@netiq. com>
          | | Subject: Undefined Value
          | | Date: Sun, 5 Oct 2003 15:40:25 -0700
          | | Lines: 37
          | | X-Priority: 3
          | | X-MSMail-Priority: Normal
          | | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
          | | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
          | | Message-ID: <OWxJsG5iDHA.11 32@tk2msftngp13 .phx.gbl>
          | | Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
          | | NNTP-Posting-Host: pat-50.bel.netiq.co m 65.219.170.50
          | | Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!tk2 msftngp13.phx.g bl
          | | Xref: cpmsftngxa06.ph x.gbl
          microsoft.publi c.dotnet.langua ges.csharp:1891 08
          | | X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
          | |
          | |
          | | Hi All,
          | |
          | | What is a best way to handle an undefined value object class that
          returned
          | | from a function. I have a function that call the ADO.NET
          ExecuteScalar()
          | | function and returns the object to the calling function as follow:
          | |
          | |
          | | public object FunctionA()
          | | {
          | | object RetVal;
          | | ... some preparation code here
          | |
          | |
          | | RetVal = ExecuteScalar() ; // This one execute a stored procedure
          | | which can return an empty column
          | |
          | | Return RetVal;
          | | }
          | |
          | |
          | | public int FunctionB()
          | | {
          | | object SingleValue;
          | | ... some code here
          | |
          | |
          | | SingleValue = FunctionA();
          | | }
          | |
          | | The call to the FunctionA works only if the ExecuteScalar() returns a
          | value.
          | | If the stored procedure returns an empty column value, and then the
          call
          | to
          | | the FunctionA() breaks out with an exception...
          | |
          | | Any thoughts????
          | |
          | |
          | |
          |
          |

          Comment

          • David N

            #6
            Re: Undefined Value

            Yeap! when the function returns a null object, the caller will have
            exception error without an opportunity to examine the object. That is
            exactly what I have in FunctionA(), which returns a null object class to
            FunctionB() - the caller. The call to

            SingleValue = FunctionA(); generates the exception error.


            // Have no chance to examine the SingleValue
            if(SingleValue == dbnull)
            ......
            ....





            "Kevin Yu" <v-kevy@online.mic rosoft.com> wrote in message
            news:A8ku467iDH A.2624@cpmsftng xa06.phx.gbl...[color=blue]
            > Hi David,
            >
            > I'm sorry that I made a mistake in my former post. If the return value of
            > the function is a Int32 type. We cannot use
            >
            > else
            > return null;
            >
            > Because Int32 is a value ype.
            >
            > Sorry for my mistake.
            >
            > Kevin Yu
            > =======
            > "This posting is provided "AS IS" with no warranties, and confers no
            > rights."
            >
            > --------------------
            > | X-Tomcat-ID: 46502818
            > | References: <OWxJsG5iDHA.11 32@tk2msftngp13 .phx.gbl>
            > | MIME-Version: 1.0
            > | Content-Type: text/plain
            > | Content-Transfer-Encoding: 7bit
            > | From: v-kevy@online.mic rosoft.com (Kevin Yu)
            > | Organization: Microsoft
            > | Date: Mon, 06 Oct 2003 02:47:42 GMT
            > | Subject: RE: Undefined Value
            > | X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
            > | Message-ID: <6CnP6Q7iDHA.68 8@cpmsftngxa06. phx.gbl>
            > | Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
            > | Lines: 60
            > | Path: cpmsftngxa06.ph x.gbl
            > | Xref: cpmsftngxa06.ph x.gbl[/color]
            microsoft.publi c.dotnet.langua ges.csharp:1891 32[color=blue]
            > | NNTP-Posting-Host: TOMCATIMPORT1 10.201.218.122
            > |
            > | Hi David,
            > |
            > | IDbCommand.Exec uteScalar Method returns the first column of the first[/color]
            row[color=blue]
            > | in the resultset. If there are no rows returned from your command, a[/color]
            null[color=blue]
            > | reference is returned. If the first column of the first row is a (Null)
            > | value, a System.DBNull object is returned. So, if you want to determine
            > if
            > | any object is returned from the ExecuteScalar() method, you can try the
            > | following codes:
            > |
            > | command.Connect ion.Open();
            > | Object o = com.ExecuteScal ar();
            > | com.Connection. Close();
            > | if(o != null && o != System.DBNull.V alue)
            > | return (Int32)o;
            > | else
            > | return null;
            > |
            > | Does this answer your question? If anything is unclear, please feel free
            > to
            > | reply to the post.
            > |
            > | Kevin Yu
            > | =======
            > | "This posting is provided "AS IS" with no warranties, and confers no
            > | rights."
            > |
            > | --------------------
            > | | From: " David N" <dq.ninh@netiq. com>
            > | | Subject: Undefined Value
            > | | Date: Sun, 5 Oct 2003 15:40:25 -0700
            > | | Lines: 37
            > | | X-Priority: 3
            > | | X-MSMail-Priority: Normal
            > | | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
            > | | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
            > | | Message-ID: <OWxJsG5iDHA.11 32@tk2msftngp13 .phx.gbl>
            > | | Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
            > | | NNTP-Posting-Host: pat-50.bel.netiq.co m 65.219.170.50
            > | | Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!tk2 msftngp13.phx.g bl
            > | | Xref: cpmsftngxa06.ph x.gbl
            > microsoft.publi c.dotnet.langua ges.csharp:1891 08
            > | | X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
            > | |
            > | |
            > | | Hi All,
            > | |
            > | | What is a best way to handle an undefined value object class that
            > returned
            > | | from a function. I have a function that call the ADO.NET
            > ExecuteScalar()
            > | | function and returns the object to the calling function as follow:
            > | |
            > | |
            > | | public object FunctionA()
            > | | {
            > | | object RetVal;
            > | | ... some preparation code here
            > | |
            > | |
            > | | RetVal = ExecuteScalar() ; // This one execute a stored procedure
            > | | which can return an empty column
            > | |
            > | | Return RetVal;
            > | | }
            > | |
            > | |
            > | | public int FunctionB()
            > | | {
            > | | object SingleValue;
            > | | ... some code here
            > | |
            > | |
            > | | SingleValue = FunctionA();
            > | | }
            > | |
            > | | The call to the FunctionA works only if the ExecuteScalar() returns a
            > | value.
            > | | If the stored procedure returns an empty column value, and then the
            > call
            > | to
            > | | the FunctionA() breaks out with an exception...
            > | |
            > | | Any thoughts????
            > | |
            > | |
            > | |
            > |
            > |
            >[/color]


            Comment

            • Kevin Yu

              #7
              Re: Undefined Value

              Hi David,

              Did you mean that the exception was thrown from FunctionA()? If so, you
              have to use a Try block in FunctionA().
              Please try to write FunctionA() as the code snippet I wrote in my last
              post, and put it in a Try block. If any exception is thrown, it will be
              caught in the Catch block.

              Try
              command.Connect ion.Open();
              Object o = com.ExecuteScal ar();
              com.Connection. Close();
              if(o != null && o != System.DBNull.V alue)
              return (Int32)o;
              else
              return 0;
              Catch
              return 0;

              In my code 0 is the error code. No exception will be thrown out of
              FunctionA().

              Kevin Yu
              =======
              "This posting is provided "AS IS" with no warranties, and confers no
              rights."

              --------------------
              | From: " David N" <dq.ninh@netiq. com>
              | References: <OWxJsG5iDHA.11 32@tk2msftngp13 .phx.gbl>
              <6CnP6Q7iDHA.68 8@cpmsftngxa06. phx.gbl>
              <A8ku467iDHA.26 24@cpmsftngxa06 .phx.gbl>
              | Subject: Re: Undefined Value
              | Date: Mon, 6 Oct 2003 09:41:58 -0700
              | Lines: 149
              | X-Priority: 3
              | X-MSMail-Priority: Normal
              | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
              | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
              | Message-ID: <O0vpDjCjDHA.23 28@TK2MSFTNGP12 .phx.gbl>
              | Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
              | NNTP-Posting-Host: pat-50.bel.netiq.co m 65.219.170.50
              | Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP12.phx.g bl
              | Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:1892 99
              | X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
              |
              | Yeap! when the function returns a null object, the caller will have
              | exception error without an opportunity to examine the object. That is
              | exactly what I have in FunctionA(), which returns a null object class to
              | FunctionB() - the caller. The call to
              |
              | SingleValue = FunctionA(); generates the exception error.
              |
              |
              | // Have no chance to examine the SingleValue
              | if(SingleValue == dbnull)
              | .....
              | ...
              |
              |
              |
              |
              |
              | "Kevin Yu" <v-kevy@online.mic rosoft.com> wrote in message
              | news:A8ku467iDH A.2624@cpmsftng xa06.phx.gbl...
              | > Hi David,
              | >
              | > I'm sorry that I made a mistake in my former post. If the return value
              of
              | > the function is a Int32 type. We cannot use
              | >
              | > else
              | > return null;
              | >
              | > Because Int32 is a value ype.
              | >
              | > Sorry for my mistake.
              | >
              | > Kevin Yu
              | > =======
              | > "This posting is provided "AS IS" with no warranties, and confers no
              | > rights."
              | >
              | > --------------------
              | > | X-Tomcat-ID: 46502818
              | > | References: <OWxJsG5iDHA.11 32@tk2msftngp13 .phx.gbl>
              | > | MIME-Version: 1.0
              | > | Content-Type: text/plain
              | > | Content-Transfer-Encoding: 7bit
              | > | From: v-kevy@online.mic rosoft.com (Kevin Yu)
              | > | Organization: Microsoft
              | > | Date: Mon, 06 Oct 2003 02:47:42 GMT
              | > | Subject: RE: Undefined Value
              | > | X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
              | > | Message-ID: <6CnP6Q7iDHA.68 8@cpmsftngxa06. phx.gbl>
              | > | Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
              | > | Lines: 60
              | > | Path: cpmsftngxa06.ph x.gbl
              | > | Xref: cpmsftngxa06.ph x.gbl
              | microsoft.publi c.dotnet.langua ges.csharp:1891 32
              | > | NNTP-Posting-Host: TOMCATIMPORT1 10.201.218.122
              | > |
              | > | Hi David,
              | > |
              | > | IDbCommand.Exec uteScalar Method returns the first column of the first
              | row
              | > | in the resultset. If there are no rows returned from your command, a
              | null
              | > | reference is returned. If the first column of the first row is a
              (Null)
              | > | value, a System.DBNull object is returned. So, if you want to
              determine
              | > if
              | > | any object is returned from the ExecuteScalar() method, you can try
              the
              | > | following codes:
              | > |
              | > | command.Connect ion.Open();
              | > | Object o = com.ExecuteScal ar();
              | > | com.Connection. Close();
              | > | if(o != null && o != System.DBNull.V alue)
              | > | return (Int32)o;
              | > | else
              | > | return null;
              | > |
              | > | Does this answer your question? If anything is unclear, please feel
              free
              | > to
              | > | reply to the post.
              | > |
              | > | Kevin Yu
              | > | =======
              | > | "This posting is provided "AS IS" with no warranties, and confers no
              | > | rights."
              | > |
              | > | --------------------
              | > | | From: " David N" <dq.ninh@netiq. com>
              | > | | Subject: Undefined Value
              | > | | Date: Sun, 5 Oct 2003 15:40:25 -0700
              | > | | Lines: 37
              | > | | X-Priority: 3
              | > | | X-MSMail-Priority: Normal
              | > | | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
              | > | | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
              | > | | Message-ID: <OWxJsG5iDHA.11 32@tk2msftngp13 .phx.gbl>
              | > | | Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
              | > | | NNTP-Posting-Host: pat-50.bel.netiq.co m 65.219.170.50
              | > | | Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!tk2 msftngp13.phx.g bl
              | > | | Xref: cpmsftngxa06.ph x.gbl
              | > microsoft.publi c.dotnet.langua ges.csharp:1891 08
              | > | | X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
              | > | |
              | > | |
              | > | | Hi All,
              | > | |
              | > | | What is a best way to handle an undefined value object class that
              | > returned
              | > | | from a function. I have a function that call the ADO.NET
              | > ExecuteScalar()
              | > | | function and returns the object to the calling function as follow:
              | > | |
              | > | |
              | > | | public object FunctionA()
              | > | | {
              | > | | object RetVal;
              | > | | ... some preparation code here
              | > | |
              | > | |
              | > | | RetVal = ExecuteScalar() ; // This one execute a stored
              procedure
              | > | | which can return an empty column
              | > | |
              | > | | Return RetVal;
              | > | | }
              | > | |
              | > | |
              | > | | public int FunctionB()
              | > | | {
              | > | | object SingleValue;
              | > | | ... some code here
              | > | |
              | > | |
              | > | | SingleValue = FunctionA();
              | > | | }
              | > | |
              | > | | The call to the FunctionA works only if the ExecuteScalar() returns
              a
              | > | value.
              | > | | If the stored procedure returns an empty column value, and then the
              | > call
              | > | to
              | > | | the FunctionA() breaks out with an exception...
              | > | |
              | > | | Any thoughts????
              | > | |
              | > | |
              | > | |
              | > |
              | > |
              | >
              |
              |
              |

              Comment

              Working...