Best way to populate an object from a datareader

  • Thread starter Thread starter Damian
  • Start date Start date
D

Damian

I may be going a bit crazy, but could someone please give me a
definitve way to poplate an object from an SqlDataReader. Do i use
DataReader.GetString(0) with check for dbnull or
Convert.ToString(dr[0]) or is there a better way?
 
See
5/24/2006 ENTRY
http://sholliday.spaces.live.com/blog/
Custom Objects/Collections and Tiered Development

In the code, I use an IDataReader .. the "Get" methods, to populate objects
and collections.

You should use the explicit datatype if you know it.

GetString
GetDecimal
GetDateTime

If you' dont know it, you can use the generic GetValue ~TO FIGURE OUT THE
DATATYPE, but not as the final solution.
 
Back
Top