I'm searching a method for setting dynamically the values of a list of variables whose names and values are readed from a database.
I've found a lot of code for getting the variable name and value, but nothing that works for setting the value.
I'll try to explain myself better. Think to have a database that contains two columns, say "name" and "value". Say for example that you have two records:
1) Name="string1", Value="message1" 2) Name="string2", Value="message2"
I have the code to read the two records, what i want is a way to take dinamically the names of the variables from the records and assign to them the corresponding values.
The code is this:
SqlCommand cmd = new SqlCommand("Select Name, " + lng + " from dbo.traductions", Global.languageconn);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
var v1 = dr["Name"].ToString();
var v2 = dr[lng].ToString();
//Something here to assign the value stored in v2 to the variable whose name is stored in v1
}
Thank you all