This article describes filling a "Data class" using a generic method. Reflection is used to find the property of any passed class dynamically and assign the value. The below approach will be very userful in large applications where hundreds of classes have to be filled throughout the flow.
Consider you have a data class called "Person" which contains below listed properties
{Name, Address, City, State, Country} . If this data object has to be filled the usual way is to get a datareader or dataset and assign the values directly.
{Name, Address, City, State, Country} . If this data object has to be filled the usual way is to get a datareader or dataset and assign the values directly.
But this new strategy iterates through each and every property of any passed object and assigns value from datareader automatically.
UI
- Person person = new Person();
- DAL dal = new DAL();
- //Pass object as a parameter
- dal.ExecuteDataReader(person, "a");
- Response.Write("Name: " + person.Name + "<br>");
- Response.Write("Address: " + person.Address + "<br>");
- Response.Write("City: " + person.City + "<br>");
- Response.Write("State: " + person.State + "<br>");
- Response.Write("Country: " + person.Country + "<br>");
DAL

w GrimmPosted Jul 20, 2017, 2:09 PM
No Function dal.ExecuteDataReader exist in the sample.