B
Brent
I can't seem to locate any easy way to create dynamic class properties.
Essentially, I want to take the column headers from a data result set,
create a property having the column header name, and then set the value
of the property to the data in the corresponding field.
For example, if I had this row from table "users":
ID Name Age
1 Barry 35
2 Brenda 33
....I could then write a SQL statement, e.g., "SELECT * from users where
ID = 2"
....and then pass it through a class
Users myuser = new Users();
that would loop through the column names, creating the properties Name
and Age (right there!) and then setting the property value by looping
through the values. Accessing the "Users" class would yield...
Users.Name = Brenda
Users.Age = 33
What I'm trying to avoid is typing out 100 column header names, and then
having to add or subtract more names as the database changes...also, I
could create classes out of any-ol'-table much easier.
I'd sure appreciate some help!
--Brent
Essentially, I want to take the column headers from a data result set,
create a property having the column header name, and then set the value
of the property to the data in the corresponding field.
For example, if I had this row from table "users":
ID Name Age
1 Barry 35
2 Brenda 33
....I could then write a SQL statement, e.g., "SELECT * from users where
ID = 2"
....and then pass it through a class
Users myuser = new Users();
that would loop through the column names, creating the properties Name
and Age (right there!) and then setting the property value by looping
through the values. Accessing the "Users" class would yield...
Users.Name = Brenda
Users.Age = 33
What I'm trying to avoid is typing out 100 column header names, and then
having to add or subtract more names as the database changes...also, I
could create classes out of any-ol'-table much easier.
I'd sure appreciate some help!
--Brent