Linq To Sql 为什么第一个方法成功修改了数据,而第二个方法不行(代码如下):
//User是数据表,“ID”是主键,传入参数是更改后的数据方法一:publicstaticboolEditUser(UseruserToBeEdi){DataClass...
//User是数据表,“ID”是主键,传入参数是更改后的数据
方法一:
public static bool EditUser(User userToBeEdi)
{
DataClasses1DataContext dc = new DataClasses1DataContext();
User edit = dc.User.Single(c=>c.ID ==userToBeEdi.ID);
edit.年龄 = userToBeEdi.年龄;
edit.性别 = userToBeEdi.性别;
edit.姓名 = userToBeEdi.姓名;
dc.SubmitChanges();
return true;
}
方法二:
public static bool EditUser(User userToBeEdi)
{
DataClasses1DataContext dc = new DataClasses1DataContext();
User edit = dc.User.Single(c=>c.ID ==userToBeEdi.ID);
edit = userToBeEdi;
dc.SubmitChanges();
return true;
} 展开
方法一:
public static bool EditUser(User userToBeEdi)
{
DataClasses1DataContext dc = new DataClasses1DataContext();
User edit = dc.User.Single(c=>c.ID ==userToBeEdi.ID);
edit.年龄 = userToBeEdi.年龄;
edit.性别 = userToBeEdi.性别;
edit.姓名 = userToBeEdi.姓名;
dc.SubmitChanges();
return true;
}
方法二:
public static bool EditUser(User userToBeEdi)
{
DataClasses1DataContext dc = new DataClasses1DataContext();
User edit = dc.User.Single(c=>c.ID ==userToBeEdi.ID);
edit = userToBeEdi;
dc.SubmitChanges();
return true;
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询