0

Hi,
I have

SessionData sdc = new SessionData();

And all the properties of sdc are stored in a table in sql server.

I want to retrieve the properties of the sdc dynamically.
And i know

sdc. reader1["xmlname"]=

is a wrong way of doing it. So can any one help me how to proceed.

Thanks

3
Contributors
6
Replies
8
Views
7 Years
Discussion Span
Last Post by sniigg
0

Hi,

Thanks for you help but I think i know the ado.net concepts.

As I said earlier the properties of sdc are in in the database.

for ex:

sdc.IsSkySports = chkSportsTV.Checked;
   sdc.IsPremiumMovies = chkMoviesTV.Checked;
 sdc.IsRecordableBox = chkRecordableBox.Checked;

In my case
IsSkySports
IsPremiumMovies

IsRecordableBox

are saved in the database table ...

And i have to acess then dynamically...

I have written the stored procedures and everything...but i dont know the c# syntax to get those from the database and apply it as properties of the object sdc..

Please help..This is really urgent

Thanks in Advance

0

yes..even the values are stored...but for now i want to access the properties....

0

so basically the resultset of your query contains the propertyname you want to access then use it with your object.

you can use System.Reflection.PropertyInfo

string propName = YourDataReader.GetString(GetOrdinal("PropertyName", dr))

PropertyInfo info = YourObject.GetType().GetProperty(propName);

for getting of the property value
object obj = info.GetValue(YourObject, null);

for setting of the property value
object obj = info.SetValue(YourObject, YourValue, null);

here is a link for Reflection:
http://www.switchonthecode.com/tutorials/csharp-tutorial-using-reflection-to-get-object-information

Edited by zid8ne: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.