日期:2014-05-20  浏览次数:20791 次

LINQ 更新不上去
public string UpdateUsers(string empName, string empId, string PowerName, string ProvinceName)
  {
  aspnet_Users users = fis.aspnet_Users.Single(p => p.UserName == empName);
  users.PowerName = PowerName;
  users.ProvinceName = ProvinceName;
  users.empId = empId;
  try
  {
  fis.SubmitChanges();
  }
  catch (Exception ex)
  {
  return "更新失败!";
  }
  return "更新成功!";
  }  
求助各位达人!!!

------解决方案--------------------
C# code

string command = "update table set id = '' where id =''";
fis.SubmitChanges();

------解决方案--------------------
private DataContext context = new DataContext();
public void U_User(User user)
{
User userA = context.User.Single(c=>c.UserID == user.UserID);
userA.UserID = user.UserID;
userA.UserName = user.UserName;
context.SubmitChanges();
}


------解决方案--------------------
把aspnet_Users换为var试下
public string UpdateUsers(string empName, string empId, string PowerName, string ProvinceName) 
{
var users = fis.aspnet_Users.Single(p => p.UserName == empName); 
users.PowerName = PowerName; 
users.ProvinceName = ProvinceName; 
users.empId = empId; 
try 

fis.SubmitChanges(); 

catch (Exception ex) 

return "更新失败!"; 

return "更新成功!"; 
}
------解决方案--------------------
楼主,出错信息要发出来,这样谁知道是什么问题呀。
------解决方案--------------------
public static bool UpdateUsers(string empName, string empId, string PowerName, string ProvinceName)
{
try
{
var n=fis.aspnet_Users.Single(p => p.UserName == empName);

n.PowerName = PowerName;
n.ProvinceName = ProvinceName;
n.empId = empId;
db.SubmitChanges();
return true;
}
catch
{
return false;
}
}
 
你这样写看对不对,
还有,你为什么以名字为查询条件,为什么不用ID,用名字,你确保是一条吗?若不是一条,就会出错
还有,我介意你,用实体传参public static bool UpdateUsers(实体名);