The variable sbSQL is an SQL SELECT SUM() statement with a while condition. The while condition may return no records. This code works fine when records are returned but throws the error listed below when the while condition returns no records.
sql = sbSQL.ToString();
SqlCommand comm = new SqlCommand(sql, conn);
comm.Connection.Open();
SqlDataReader r = comm.ExecuteReader(CommandBehavior.CloseConnection);
while(r.Read())
{
double dTotal = (r.GetDouble(0));
}
This line throws the exception> double dTotal = (r.GetDouble(0));
Exception Details: System.Data.SqlTypes.SqlNullValueException: Data is Null. This method or property cannot be called on Null values.
I’ve tried some variations of IsDBNull but fear I may be headed down the wrong path. Any input will be greatly appreciated!
Thank you!
iRead