How to assign a value to variable via Reflection where var name and value are pulled

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BrianDaze

    How to assign a value to variable via Reflection where var name and value are pulled

    Hi,

    I am new to Reflection in C#, and hoping someone could give me pointers on how to set a variable using Reflection. The variable name, type, and value are stored in a sql server database table. I am using a sql stored proc to pull the variable name, data type (int and string), and value from the DB then I want to loop through the result set and assign the values to the variables (that have already been declared at design time in the ASP.net aspx.cs).

    I have googled this for a couple of days and have gotten close but have not been able to get exactly what I need.

    Any help is greatly appreciated.

    Brian
  • GaryTexmo
    Recognized Expert Top Contributor
    • Jul 2009
    • 1501

    #2
    Try taking a look a the InvokeMember method on the type of a class...

    Code:
    typeof(TheClassType).InvokeMember(...)

    Comment

    Working...