Skip to content

Latest commit

 

History

History
45 lines (41 loc) · 1.22 KB

README.md

File metadata and controls

45 lines (41 loc) · 1.22 KB

AdoNetSafeGet

Build Status

AdoNetSafeGet is a set of an extension method for IDataReader interface that provides a safe and clean way how to read data from data reader.

Features:

  • Convenient strong type access to column value by name.
while(dataReader.Read){
    string city = dataReader.SafeGetString("Name");
}

instead of

while(dataReader.Read){
  int cityColumnIndex = dataReader.GetOrdinal("Name"); 
  string city = dataReader.GetString(cityColumnIndex);
}
  • efficient and clear way to handle DBNull values.
while(dataReader.Read){
    string city = dataReader.SafeGetString("Name");
}

instead of

while(dataReader.Read)
{
  if (row["value"] != DBNull.Value)
  {
    someObject.Member = row["value"];
  }
}
  • Abbility to specify default value if value is DBNull.
while(dataReader.Read){
    string city = dataReader.SafeGetString("Name", "default string value");
}

NB!

If you wouldn't specify a default value, the type default value will be returned.