日期:2014-05-17 浏览次数:20522 次
HBSIEntities entity = new HBSIEntities();
/*更改表的实体,注意在最后加上了“Id=7”,
标识要更改实体表T_UserInfo中Id=7的行实体,
为字段重新赋值即可*/
T_UserInfo userinforow = new T_UserInfo()
{
UserName = "zbj",
Pwd = "234567",
NickName = "二师兄",
Address = "高老庄",
Sfzh = "123452223333444423",
Id=7
};
entity.T_UserInfo.Attach(userinforow);
entity.ObjectStateManager.ChangeObjectState(userinforow,EntityState.Modified);
entity.SaveChanges();
HBSIEntities entity = new HBSIEntities();
/*更改表的实体,注意在最后加上了“Id=7”,
标识要更改实体表T_UserInfo中Id=7的行实体,
为字段重新赋值即可*/
T_UserInfo userinforow = new T_UserInfo()
{
UserName = "zbj",
Pwd = "234567",
NickName = "二师兄",
Address = "高老庄",
Sfzh = "123452223333444423",
Id=7
};
entity.T_UserInfo.Attach(userinforow); //////这句去掉 因为你查询的时候这个对象已经Attach过了