I have a table "Users".. it has a column "ShowData"
using linq-sql how can I loop through every user and set ShowData to false for each user..
thanks
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");
}
Create a stored procedure
CREATE PROCEDURE HideData
AS
update Users set ShowData = 0
Using your server explorer dropdown this procedure in your Dbml
And in your function:
using (CustomDataContext context= new CustomDataContext())
{
context.HideData();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With