开发者

Insert into all columns of int same value

开发者 https://www.devze.com 2023-03-07 20:27 出处:网络
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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消