开发者

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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜