A
Anodes
How do I test for and handle a return of null in the following code?
try
{
OleDbConnection connection = new
OleDbConnection(connectionString);
connection.Open();
OleDbCommand command = new OleDbCommand(SQL_Query,
connection);
scalarReturned =
command.ExecuteScalar().ToString();
command.Dispose();
connection.Close();
}
catch (Exception ex)
{
}
This is part of a data-handling class I'm building, and I use this
method for pulling single values from one of my lookup tables where
the structure is fixed. It works fine; however I want to be able to
handle when the query returns null...of course trying to convert null
ToString() generates an error.
I suppose I could just trap that error, but I'd rather design it so no
error is generated.
Thanks.
try
{
OleDbConnection connection = new
OleDbConnection(connectionString);
connection.Open();
OleDbCommand command = new OleDbCommand(SQL_Query,
connection);
scalarReturned =
command.ExecuteScalar().ToString();
command.Dispose();
connection.Close();
}
catch (Exception ex)
{
}
This is part of a data-handling class I'm building, and I use this
method for pulling single values from one of my lookup tables where
the structure is fixed. It works fine; however I want to be able to
handle when the query returns null...of course trying to convert null
ToString() generates an error.
I suppose I could just trap that error, but I'd rather design it so no
error is generated.
Thanks.