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 2 5215
> 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" <GM***@dublin.com> wrote in message
news:MP************************@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 <pV*****************@newsread1.news.atl.earthlink. net>, da*******@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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Nachi |
last post by:
I am getting 2 resultsets depending on conditon, In the second
conditon i am getting the above error could anyone help me..........
CREATE proc sp_count_AllNewsPapers
@CustomerId int
as...
|
by: Ly Lam |
last post by:
In my .resx file (below) I wish to reference an external bitmap that is
located in my project's folder. When I try to compile the project I get an
error on my .resx file:
Resource...
|
by: Dave |
last post by:
Hi everyone,
(I already posted this to the VS.NET IDE news group without any responses, so I'm attempting one more time in this group)
The issue I'm having is occuring in the IDE of VS.NET...
|
by: I am dog |
last post by:
Hi ,
I use VS 2005 beta1 to do some thing as follows.
declare a Dictionary<ulong,DelegateTyep> dictionary = new ...
and use dictionary object such as
dictionary += aDelegateTyepObject;
|
by: Edward Diener |
last post by:
I really do not understand the difference between the <summary> and <value>
XML document tags for a property. Why would one use one as opposed to the
other for a property, and when would one use...
| |
by: Mehdi |
last post by:
Hi,
I have a datagrid which is populated by a dataset. I have a column
containing LinkButton that passes MyID and fires my event handler...
....
<ItemTemplate>
<asp:LinkButton id="btnEdit"...
|
by: Joseph Geretz |
last post by:
Why isn't the ASP.NET runtime providing a valid reference for this object to
my WebService? I'm trying to use WSE and DIME to send attachments via Web
Service. I've provided a whole lot of...
|
by: magix |
last post by:
Hi,
in my SELECT (like below), the option value has 2 values, separated with
comma ","
<select name="sIdName">
<option value="10,John">John</option>
<option value="11,Eva">Eva</option>...
|
by: Akino877 |
last post by:
Hello,
I am new to HTML and PHP. And I am trying to assign an array of values to the
<option value=...> of a combo list. But what I am trying to do is not working. I
can sucessfully get it to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |