Unix Technical Forum

<undefined value>

This is a discussion on <undefined value> within the SQL Server forums, part of the Microsoft SQL Server category; --> Greetings, I asked this question over on the ADO.NET newsgroup and couldn't scrape up an answer. I realize that ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 06:15 PM
Guinness Mann
 
Posts: n/a
Default <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.ExecuteScalar 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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 06:15 PM
Dan Guzman
 
Posts: n/a
Default Re: <undefined value>

> How do I do test for that condition?

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

--
Hope this helps.

Dan Guzman
SQL Server MVP

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

http://www.ntfaq.com/Articles/Index....partmentID=800
http://www.sqlserverfaq.com
http://www.mssqlserver.com/faq
-----------------------

"Guinness Mann" <GMann@dublin.com> wrote in message
news:MPG.19edf588afa984d79896f5@news.newsguy.com.. .
> 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.ExecuteScalar 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
>



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 06:16 PM
Guinness Mann
 
Posts: n/a
Default Re: <undefined value>

In article <pV4hb.9598$mQ2.8310@newsread1.news.atl.earthlink. net>,
danguzman@nospam-earthlink.net says...
> > How do I do test for that condition?

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


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

Here's what I've been doing:

Object myScalarResult = myCommand.ExecuteScalar();
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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 02:52 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com