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 2 5233
> 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): http://www.ntfaq.com/Articles/Index....partmentID=800 http://www.sqlserverfaq.com http://www.mssqlserver.com/faq
-----------------------
"Guinness Mann" <GM***@dublin.c om> 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.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
In article <pV************ *****@newsread1 .news.atl.earth link.net>, da*******@nospa m-earthlink.net says... How do I do test for that condition?
Object myScalarResult = myCommand.Execu teScalar(); 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.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 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
declare @NewsId int
set @NewsId = (select NewsDelId from NewsDelivery where
CustomerId=@CustomerId )
|
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 transformation for file 'Images.resX' failed. Could not find file
"C:\Program Files\Microsoft Visual Studio .NET
2003\Common7\IDE\TEditButton.bmp".
It seems like the resource compiler has a base-path set to the vs.net's IDE
directory. How do I specify a...
|
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 2003, although I'm not sure what is actually causing the problem. I can't
summarize the issue, so please read on to find out more.
I've created a BaseDialogEditor class that allows a developer (namely me) to create Modal editors for controls at...
|
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 both ?
| |
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" CommandName="GoToEditPage"
CommandArgument='<%# DataBinder.Eval(Container.DataItem, "MyId")%>'
runat="server" Text="Edit"/>
|
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 information in the thread below:
DIME: Attachments.Add - Object reference not set to an instance of an
object.
Bu when all is said and done, the crux of the problem is that
ResponseSoapContext.Current = <undefined value> when I attempt to access it....
|
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>
<option value="22,Danny">Danny</option>
</select>
|
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 work if I assign each value separately.
I wonder if anyone could please help me with this problem. Below is my code.
Thank you and Best Regards,
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |