Insert into all columns of int same value
In LINQ how do i insert into all columns of type int in a table1 the same number value: 1, without specifying each column with the number (colint1, colint2, colint3, col开发者_如何学JAVAint4) ?
You can use reflection with something like this for an object 'o' and a new integer value 'newValue' (sorry, I don't have VS on this machine to test it out):
foreach(PropertyInfo prop in o.GetType().GetProperties())
{
if(prop.PropertyType == typeof(int))
prop.SetValue(o, newValue, null);
}
Then just be sure to save your changes
精彩评论