JB wrote:
if(!reader.IsDB Null(swimcol))
{
// use (string)reader[swimcol]
}
else
{
// use some default value maybe null
}
Arne
I am using a datareader to reader a table. The table may have some null
values in it. The thing is that I need to process the row whether the field
has null values in it or not. The "Swim" field in this table will have null
values in it. The problem is that when I try to read the field with a null
value I get the error message stating:
>
"unable to cast object of type 'System.DBNull' to type 'System.String' .
values in it. The thing is that I need to process the row whether the field
has null values in it or not. The "Swim" field in this table will have null
values in it. The problem is that when I try to read the field with a null
value I get the error message stating:
>
"unable to cast object of type 'System.DBNull' to type 'System.String' .
reader =
selectCommand.E xecuteReader(Co mmandBehavior.S ingleResult);
while (reader.Read())
{
WillUsedList WillUsed = new WillUsedList((i nt)reader["PoolLoc
"],(string)reader["Swims"]);
selectCommand.E xecuteReader(Co mmandBehavior.S ingleResult);
while (reader.Read())
{
WillUsedList WillUsed = new WillUsedList((i nt)reader["PoolLoc
"],(string)reader["Swims"]);
{
// use (string)reader[swimcol]
}
else
{
// use some default value maybe null
}
WillUsed. PoolAddr = (int)reader["PoolLoc"];
WillUsed. PollHeat = (string)reader["Swims"];
nuList.Add(Will Used.PoolAddr);
nuList.Add(Will Used. PollHeat);
}
reader.Close();
WillUsed. PollHeat = (string)reader["Swims"];
nuList.Add(Will Used.PoolAddr);
nuList.Add(Will Used. PollHeat);
}
reader.Close();
Comment