Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

ExecuteScalar

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
MDB - 04 Mar 2008 12:27 GMT
Hello All, what is the correct / proper way to check for null values in the
ExecuteScalar.  System.DBNull.Value, Null or both?
Misbah Arefin - 04 Mar 2008 12:54 GMT
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;
///

Signature

Misbah Arefin
https://mcp.support.microsoft.com/profile/MISBAH.AREFIN
http://www.linkedin.com/in/misbaharefin

> Hello All, what is the correct / proper way to check for null values in the
> ExecuteScalar.  System.DBNull.Value, Null or both?
MDB - 04 Mar 2008 12:59 GMT
Okay, I am not thinking straight this morning and understand now.  Thanks.

> 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
[quoted text clipped - 14 lines]
>> the
>> ExecuteScalar.  System.DBNull.Value, Null or both?

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.