473,856 Members | 1,698 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

<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

Jul 20 '05 #1
2 5239
> 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

Jul 20 '05 #2
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

Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
10552
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 )
0
1429
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...
0
1867
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...
1
2293
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;
4
3899
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 ?
0
2204
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"/>
1
2266
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....
4
10345
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>
2
7544
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,
0
11048
Oralloy
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...
0
10692
jinu1996
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...
1
10770
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,...
0
9526
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5754
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5954
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4567
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4168
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3194
bsmnconsultancy
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.