Showing posts with label valuegt. Show all posts
Showing posts with label valuegt. Show all posts

Sunday, February 19, 2012

<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> 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...epartmentID=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|||In article <pV4hb.9598$mQ2.8310@.newsread1.news.atl.earthlink.n et>,
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

<Select a Value> inconsistent

Hi, has anyone else seen this or know of why it's happening?
I have a report with a parameter Region. The region values are pulled
from a query:
select null as id, '' as name
union
select regionid, regionname from region
The Region parameter allows nulls and has a default value of null.
In the visual studio designer everything looks great. The dropdown
parameter is blank and my region values are there if I pull it down.
When I deploy the report to the server, the region parameter looks
different. It now defaults to <Select a Value>. The blank (null) line
exists but is not defaulted to on open of the report.
Another weird aspect of this is that I have a number of other reports
that "seem" to be set up exactly in this manner that work corrrectly
(i.e. The Region dropdown show up blank with valid regions in the
dropdown and no <select a value> option) in the designer and on the
server.
Thanks for your help,
BrettOn your report parameter have you set a non-queried default value of
=Nothing ?
HTH, Magendo_man
"Brett" wrote:
> Hi, has anyone else seen this or know of why it's happening?
> I have a report with a parameter Region. The region values are pulled
> from a query:
> select null as id, '' as name
> union
> select regionid, regionname from region
> The Region parameter allows nulls and has a default value of null.
> In the visual studio designer everything looks great. The dropdown
> parameter is blank and my region values are there if I pull it down.
> When I deploy the report to the server, the region parameter looks
> different. It now defaults to <Select a Value>. The blank (null) line
> exists but is not defaulted to on open of the report.
> Another weird aspect of this is that I have a number of other reports
> that "seem" to be set up exactly in this manner that work corrrectly
> (i.e. The Region dropdown show up blank with valid regions in the
> dropdown and no <select a value> option) in the designer and on the
> server.
> Thanks for your help,
> Brett
>|||Thanks magendo! That worked! I still don't understand why this
parameter acts differently than other parameters (or why setting the
default to NULL does not work), but at this point, I'm just happy it
works. Thanks a bunch.
Brett