<undefined value>

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

    <undefined value>

    Greetings,

    I asked this question over on the ADO.NET newsgroup and couldn't scrape
    up an answer. I realize that it is more of an ADO question than an SQL
    Server question, but I'm hoping there might be an ADO programmer here
    that can explain this to me.

    I'm developing database applications using C# on VS.NET 2003 and SQL
    Server Standard edition (SP3a).

    I've run into a situation I'm trying to understand, to wit, if I submit
    a query using SqlCommand.Exec uteScalar which returns no results, why is
    the returned item a System.Object of <undefined value>?

    (Actually, I think I know why -- ExecuteScalar returns a null reference
    if there are no results.)

    How do I do test for that condition?

    I guess I can sort of see why they didn't want to throw an exception --
    lot's of queries don't return any results, but on the other hand, I
    can't figure out how to test for <undefined value>, either.

    Any ideas?

    -- Rick

  • Dan Guzman

    #2
    Re: &lt;undefine d value&gt;

    > How do I do test for that condition?

    Object myScalarResult = myCommand.Execu teScalar();
    if ( myScalarResult == null )
    {
    // no result returned
    }

    --
    Hope this helps.

    Dan Guzman
    SQL Server MVP

    -----------------------
    SQL FAQ links (courtesy Neil Pike):




    -----------------------

    "Guinness Mann" <GMann@dublin.c om> wrote in message
    news:MPG.19edf5 88afa984d79896f 5@news.newsguy. com...[color=blue]
    > Greetings,
    >
    > I asked this question over on the ADO.NET newsgroup and couldn't[/color]
    scrape[color=blue]
    > up an answer. I realize that it is more of an ADO question than an[/color]
    SQL[color=blue]
    > Server question, but I'm hoping there might be an ADO programmer here
    > that can explain this to me.
    >
    > I'm developing database applications using C# on VS.NET 2003 and SQL
    > Server Standard edition (SP3a).
    >
    > I've run into a situation I'm trying to understand, to wit, if I[/color]
    submit[color=blue]
    > a query using SqlCommand.Exec uteScalar which returns no results, why[/color]
    is[color=blue]
    > the returned item a System.Object of <undefined value>?
    >
    > (Actually, I think I know why -- ExecuteScalar returns a null[/color]
    reference[color=blue]
    > if there are no results.)
    >
    > How do I do test for that condition?
    >
    > I guess I can sort of see why they didn't want to throw an[/color]
    exception --[color=blue]
    > lot's of queries don't return any results, but on the other hand, I
    > can't figure out how to test for <undefined value>, either.
    >
    > Any ideas?
    >
    > -- Rick
    >[/color]


    Comment

    • Guinness Mann

      #3
      Re: &lt;undefine d value&gt;

      In article <pV4hb.9598$mQ2 .8310@newsread1 .news.atl.earth link.net>,
      danguzman@nospa m-earthlink.net says...[color=blue][color=green]
      > > How do I do test for that condition?[/color]
      >
      > Object myScalarResult = myCommand.Execu teScalar();
      > if ( myScalarResult == null )
      > {
      > // no result returned
      > }[/color]

      Sheesh. Simple enough once you know the answer, eh? Thanks!

      Here's what I've been doing:

      Object myScalarResult = myCommand.Execu teScalar();
      int returnValue = Convert.ToInt32 (myScalarResult );

      Which returns 0 if null, otherwise the Int32 I'm looking for.
      Fortuitously, 0 is not in the possible solution set, so by coincidence,
      it works.

      Thanks again,

      -- Rick

      Comment

      Working...