F
Francois Malgreve
As the indexer (for C#, SqlDataReader.Item for VB) on the SqlDataReader
object returns an object of type Object, I need to do the following kind of
casting to get my value:
String value = (string) dataRead["FirstName"];
int age = (int) dataRead["age"];
The problem is that is the column in the DB contains a null value, the cast
will throw an exception as in that case the object returned by the indexer
is of type DbNull.
Then I do the following stuff to avoid casting excpetion:
String value = null;
if ( !(dataRead["FirstName"] is DBNull) )
{
value = (string) dataRead["FirstName"];
}
he problem of this way of doing is that, IMHO, doing a type check may be
performance costing especially as I will have tons of them as I need to do
it for any DB field I retrieve from the DB.
As my goal is just to know if the DB field contain a value or is NULL, then
my question is:
Is there a more efficient way to achieve the same goal than by checking the
type?
Thanks in advance
Francois
object returns an object of type Object, I need to do the following kind of
casting to get my value:
String value = (string) dataRead["FirstName"];
int age = (int) dataRead["age"];
The problem is that is the column in the DB contains a null value, the cast
will throw an exception as in that case the object returned by the indexer
is of type DbNull.
Then I do the following stuff to avoid casting excpetion:
String value = null;
if ( !(dataRead["FirstName"] is DBNull) )
{
value = (string) dataRead["FirstName"];
}
he problem of this way of doing is that, IMHO, doing a type check may be
performance costing especially as I will have tons of them as I need to do
it for any DB field I retrieve from the DB.
As my goal is just to know if the DB field contain a value or is NULL, then
my question is:
Is there a more efficient way to achieve the same goal than by checking the
type?
Thanks in advance
Francois