469,928 Members | 1,897 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,928 developers. It's quick & easy.

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 2912
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by WeiminZhang | last post: by
2 posts views Thread by trialproduct2004 | last post: by
7 posts views Thread by Neven Klofutar | last post: by
3 posts views Thread by charliewest | last post: by
2 posts views Thread by Manikandan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.