System.DbNull problem

  • Thread starter Thread starter MyCatAlex
  • Start date Start date
M

MyCatAlex

Guest
I have this code:

using (SqlDataReader rdr = cmdm.ExecuteReader(CommandBehavior.CloseConnection))
{
if (rdr.HasRows == true)
{
foreach (System.Data.Common.DbDataRecord row in rdr)
{
if (row[7].GetType() != System.DBNull)
{
tBoxCheckingBal_pg5.Text = (string)row[7]; // <== runtime error
}
if (row[8].GetType() != System.DBNull)
{
tBoxSavingsBal_pg5.Text = (string)row[8]; // runtime error
}

I get a Compile time error: DBNull is a type and it is invalid in the given context.

If I say null instead of DBNull, then I get a runtime error because those fields are empty, they are nulls.

What shall I do?

Continue reading...
 
Back
Top