Insert to the C#Dynamic Database?

Asked

Viewed 92 times

1

I’m making a insert and use a model with the Getters and Setters, when I do the insert in the values I receive to model as a parameter and use as follows

sql = "INSERT INTO " + Table + "(" + campos + ") VALUES ('"+valores.nome+ "','" + valores.email + "', " + valores.cpf + ", " + valores.tel + ");";

There’s a way I could pass the Dynamic Values by taking him from model ?

  • From what I understand, the values are already being passed dynamically, through the properties of the object "values".

  • Your question has become meaningless ?

1 answer

1

i do not use model, but use System.Reflection.Propertyinfo to list the properties of an object and mount my syntaxes.

 foreach (System.Reflection.PropertyInfo pr in obj.GetType().GetProperties())
 {
     if (pr.CanRead)
     {
        object valor = pr.GetValue(obj, null);
     }
}

then you just have a list of fields and the relation between the columns to apply each value correctly to your place

Browser other questions tagged

You are not signed in. Login or sign up in order to post.