Best way to populate an object from a datareader

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?
 
S

sloan

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top