插入int相同值的所有列

时间:2011-05-22 17:45:17

标签: c# wpf visual-studio linq

在LINQ中,如何在table1中的int类型的所有列中插入相同的数字值:1,而不指定每个列的数字(colint1,colint2,colint3,colint4)?

1 个答案:

答案 0 :(得分:1)

对于对象'o'和新的整数值'newValue',你可以使用这样的反射(抱歉,我没有在这台机器上用VS来测试它):

foreach(PropertyInfo prop in o.GetType().GetProperties()) 
{
    if(prop.PropertyType == typeof(int))
        prop.SetValue(o, newValue, null);
}

然后确保保存更改