R
Rbrt
I have a class with properties that correspond to the columns in a database
table. So for example the column BookTitle in table Books will have a
corresponding property BookTitle in the class Books.
I am writing a data access layer that creates a list of Book objects and so
I have to read the data from the table, and then loop through all the records
and set the properties of each instance of the Book class by getting the
corresponding value from the datatable, e.g....
If not dtBooks.Rows(intIdx)("BookTitle").Equals(DBNull.Value) then
BookInstance.BookTitle = datatableBooks.Rows(RowIndex)("BookTitle").value
end if
There are a lot of columns in the table and properties in the class and each
time I add a new column and property, I have to add new code to the data
access layer.
Is there any way to simplify the data access layer so that it can
automatically loop through the records and set the appropriate properties of
the class object just by looking at column names?
I've been trying to figure out how to do this using reflection, but it's
tough slogging.
Thanks!
table. So for example the column BookTitle in table Books will have a
corresponding property BookTitle in the class Books.
I am writing a data access layer that creates a list of Book objects and so
I have to read the data from the table, and then loop through all the records
and set the properties of each instance of the Book class by getting the
corresponding value from the datatable, e.g....
If not dtBooks.Rows(intIdx)("BookTitle").Equals(DBNull.Value) then
BookInstance.BookTitle = datatableBooks.Rows(RowIndex)("BookTitle").value
end if
There are a lot of columns in the table and properties in the class and each
time I add a new column and property, I have to add new code to the data
access layer.
Is there any way to simplify the data access layer so that it can
automatically loop through the records and set the appropriate properties of
the class object just by looking at column names?
I've been trying to figure out how to do this using reflection, but it's
tough slogging.
Thanks!