linq to sql-遍历表数据和设置值 [英] linq to sql - loop through table data and set value
本文介绍了linq to sql-遍历表数据和设置值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个表"Users". 它有一列"ShowData"
I have a table "Users".. it has a column "ShowData"
如何使用linq-sql遍历每个用户并将每个用户的ShowData设置为false.
using linq-sql how can I loop through every user and set ShowData to false for each user..
谢谢
推荐答案
创建一个linq to sql classes设计器文件.然后将用户"表放到设计器图面上.
Create a linq to sql classes designer file. Then drop the Users table on to the designer surface.
using (TheDataContext dc = new TheDataContext)
{
//pull all users into memory, not recommended for large tables.
List<User> users = dc.Users.ToList();
foreach(User theUser in users)
{
theUser.ShowData = false;
}
//send all these property changes back to the database.
dc.SubmitChanges();
}
为了防止自己投票不足:
And to guard myself against downvoting:
using (TheDataContext dc = new TheDataContext())
{
dc.ExecuteCommand("UPDATE Users SET ShowData = 0");
}
这篇关于linq to sql-遍历表数据和设置值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文