J
Jim Bancroft
Hi everyone,
My code queries a SQL Server database and retrives a single DataTable.
From that table I loop through the DataRows, reading and making use of its
columns. I convert the values to System datatypes in order to use them, but
that's not a problem.....unless one of the columns contains a null value.
The general sequence is this: 'myBoolean =
Convert.ToBoolean(DR["myColumn"])'. Substitute "ToBoolean" with other
appropriate conversions (depending on the column type) and you've got the
gist of what I'm doing. Again, these conversions work fine unless a DataRow
contains a null column value, in which case I receive an invalid cast error.
Is there any way to force System.DBNull to convert itself to a Boolean
or other type? I'm looking to avoid littering my code with "if" statements
checking for DBnull values, if possible.....thanks.
My code queries a SQL Server database and retrives a single DataTable.
From that table I loop through the DataRows, reading and making use of its
columns. I convert the values to System datatypes in order to use them, but
that's not a problem.....unless one of the columns contains a null value.
The general sequence is this: 'myBoolean =
Convert.ToBoolean(DR["myColumn"])'. Substitute "ToBoolean" with other
appropriate conversions (depending on the column type) and you've got the
gist of what I'm doing. Again, these conversions work fine unless a DataRow
contains a null column value, in which case I receive an invalid cast error.
Is there any way to force System.DBNull to convert itself to a Boolean
or other type? I'm looking to avoid littering my code with "if" statements
checking for DBnull values, if possible.....thanks.