I am new to the c# language and questions came up. i use the massive single file DB.
here you can create a class like this:
public class products : DynamicModel
{
public products(String conn) : base("northwind", "products","productid")
{
}
}
now would i do sth like this:
var products = new { Productname = "HOHOHO" };
until here everything works fine, but i want to query and update different databases and tables and so i dont know that there is a table column like "Productname" so this must be a variable:
string foo = "Productname";
var products = new { foo = "HOHOHO" };
But this would leed to the fact that the massive looks for a column "foo" because the string would not be interpreted.
How can I insert a variable here?
How is this technique named?
thanks for your help!
EDIT:
Thanks to TGH!
In combination with the massive DB the use of an NameValueCollection would solve the problem:
NameValueCollection nvc = new NameValueCollection();
nvc.Add(field, (string)fieldValue);
table.Update(nvc, keyValue);
Thank you
You can't use variables when defining properties on your anonymous objects.
I would recommend that you look into a Dictionary<string,string>
to represent this instead. A Dictionary/Hashtable is probably the most flexible way to get around the static nature of c# when it comes to dynamic variables
You can let each column name be the keys in the dictionary