SqlDataReader Problem

  • Thread starter Thread starter Andrew Jones
  • Start date Start date
A

Andrew Jones

I'm trying to read in fields from a table. How do I handle fields that are
blank?
How do I know how to skip the field? I'm getting

Invalid attempt to read when no data is present. Errors.

I've tried this with both blank fields and ones with spaces and they both
seem to fail the same way.

Andrew
 
If you have a DB that supports nulls, then you are probably running into
null values. You can compare fields to DBNull.Value
if (rdr["fieldName"] != DBNull.Value)
{
// Process record
}

When processing keep in mind that many DB types such as (Small)DateTime,
int, tinyint, smallint, etc. do not have .NET primitive equivalents.

So in my .NET apps I normally assign key values such as
DateTime.MinValue to represent database nulls. There's no .NET support
for null primitives.
 
Back
Top