473,383 Members | 1,733 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

ExecuteScalar

MDB
Hello All, what is the correct / proper way to check for null values in the
ExecuteScalar. System.DBNull.Value, Null or both?

Mar 4 '08 #1
2 3051
it really depends on what you need to find out about the result
if you need to test if a the row/data exists then just check for null and
you need to test if the row/data exists and has a valid value then try the
following

///
object result = cmd.ExecuteScalar();

if (result == null)
return "Customer not found";
if (result == System.DBNull.Value)
return "Customer found but name is null";
return (string) result;
///
--
Misbah Arefin
https://mcp.support.microsoft.com/profile/MISBAH.AREFIN
http://www.linkedin.com/in/misbaharefin
"MDB" wrote:
Hello All, what is the correct / proper way to check for null values in the
ExecuteScalar. System.DBNull.Value, Null or both?

Mar 4 '08 #2
MDB
Okay, I am not thinking straight this morning and understand now. Thanks.

"Misbah Arefin" <Mi**********@discussions.microsoft.comwrote in message
news:F1**********************************@microsof t.com...
it really depends on what you need to find out about the result
if you need to test if a the row/data exists then just check for null and
you need to test if the row/data exists and has a valid value then try the
following

///
object result = cmd.ExecuteScalar();

if (result == null)
return "Customer not found";
if (result == System.DBNull.Value)
return "Customer found but name is null";
return (string) result;
///
--
Misbah Arefin
https://mcp.support.microsoft.com/profile/MISBAH.AREFIN
http://www.linkedin.com/in/misbaharefin
"MDB" wrote:
>Hello All, what is the correct / proper way to check for null values in
the
ExecuteScalar. System.DBNull.Value, Null or both?

Mar 4 '08 #3

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

Similar topics

3
by: cmo63126 | last post by:
Why am I not able to retrieve the value of ID (which does exist) using ExecuteScalar()? Do i simply have to use ExecuteReader() instead? My problem snippet: string mySQL = "SELECT ID FROM...
2
by: WeiminZhang | last post by:
When I use the OleDb to connect a Oracle db, and use the ExecutScalar() method to get the count of a table, the return value can't be cast to a data type, say int, while this works fine for a SQL...
3
by: AL | last post by:
Hello. I've been programming in C# for about 6 months, and I have a question; I was experimenting with some code this evening, for example this; this.sqlConnection1.Open(); int qty = (int)...
2
by: Dinesh | last post by:
Hi, I have one stored procedure in SQL server in which i have written one insert statement. Now in my cs file i pass the parameters require to execute that stored procedure and finaly by mistaken...
2
by: trialproduct2004 | last post by:
hi all i am having application which is connecting to databset and executing one query as below:- string str; str="select count(*) from table1; and then i am using sqlcommand to get result...
6
by: Max | last post by:
Anyone know why I'm always getting 0 returned? My stored procedure returns -1. Dim iErrorCode As Int32 iErrorCode = Convert.ToInt32(SqlHelper.ExecuteScalar(AppVars.strConn, _ "gpUpdateMember",...
7
by: Neven Klofutar | last post by:
Hi, I have a problem with SqlHelper.ExecuteScalar ... When I try to execute SqlHelper.ExecuteScalar I get this message: "System.InvalidCastException: Object must implement IConvertible.". ...
5
by: bienwell | last post by:
Hi all, I have a problem with using myCommand.ExecuteScalar(). My question is : If the Web setup is incorrect, does it make command ExecuteScalar() work improperly ?? In my program, I was...
3
by: charliewest | last post by:
Hi - I need to detect when the ExecuteScalar() method of the cmd object returns NULL. I have tried the below code, however, it always returns false (this is to say, that ExecuteScalar never...
2
by: Manikandan | last post by:
Hi, I have a table with following data Tablename:details No(varchar) Name(varchar) Updated(Datetime) 1 mm 10/10/2006 2 nn 02/12/2005 3 kk NULL I'm using executescalar to get the...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.