Reading Data into objects

  • Thread starter Thread starter Chris Dunaway
  • Start date Start date
C

Chris Dunaway

I have a table in the database called Users and it has typical fields
(UserId, UserName, etc.).

I created a User class with properties that match the fields in the table.

What I want to do is read a row from the table and create an instance of
the User class, populated with the data from that row.

I can manually set the values of each property in the class from a
DataReader for example, but I was wondering if there was an easier way to
do it.

Is there a way to read a row "directly into" and object instance? Or must
I just bite the bullet and do it manually?

Or am I completely off on the wrong tangent?
 
I'm no expert here but it seems to me that you could add
an additional property to your User Class

Dim dR As DataRow
Public Property dtRow() As DataRow
Get
Return dR
End Get
Set(ByVal Value As DataRow)
dR = Value
End Set
End Property

When you invoke your User class object
Dim usr as New User
....
usr.drRow = dataset(...) 'datareader whatever

then populate your User vars with the contents of dR.
Just a thought.

Rich
 
Back
Top