ExecuteScalar

  • Thread starter Thread starter MDB
  • Start date Start date
M

MDB

Hello All, what is the correct / proper way to check for null values in the
ExecuteScalar. System.DBNull.Value, Null or both?
 
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;
///
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top