i am trying to update a user table with a single value update, but i can’t figure out what i’m doing wrong. this is what i have:
public static void ApplyROB(string ROBread, string userName)
{
using (SERTEntities ctx = CommonSERT.GetSERTContext())
{
// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
// Audit of the transfer
datUser trUser = new datUserRole();
trUser.ROB = ROBread;
trUser.AccountName = userName;
// Persist update to DB
ctx.SaveChanges();
}
}
am i way off? nothing happens when i click on the update.
how do i say, where username = username? did i do it right?
basically in need a simple:
update datUser set ROB = "Y" where AccountName= "myusername"
it’s turning out to be a bit more complicated in LINQ using Context
please help.
You’re not adding your new entity to the context, thus when you save, the context is unaware of any changes. You need something like…
To do an update, you need to retreive an entity from the context, make changes to it, then save… so: