看到这个问题,首先检查SQL语句是否缺少 “ ‘ ”号,,如何SQL语句没有错误,就检查得到的数据中是否有单引号(“ ‘ ”)、双引号(“ “ ”)等

如何得到的数据有单双引号,就用 SQL连接法对数据进行操作。SQL连接法符号是  “ @ ”。

例如

1 string sql = "update Users set " + "UserRoleId=@UserRoleId," + "UserStateId=@UserStateId," + "LoginId=@LoginId," + "LoginPwd=@LoginPwd," + "Name=@Name," + "Address=@Address," + "Phone=@Phone," + "Mail=@Mail " +" where Id=@Id";
 2             SqlParameter[] para = new SqlParameter[]
 3             {
 4                 new SqlParameter("@Id",us.Id),
 5                 new SqlParameter("@LoginId",us.LoginId),
 6                 new SqlParameter("@LoginPwd",us.LoginPwd),
 7                 new SqlParameter("@Name",us.Name),
 8                 new SqlParameter("@Address",us.Address),
 9                 new SqlParameter("@Phone",us.Phone),
10                 new SqlParameter("@Mail",us.Mail),
11                 new SqlParameter("@UserStateId",us.UserStates.Id), //FK
12                 new SqlParameter("@UserRoleId",us.UserRoles.Id) //FK
13              };
14             DBHelper.ExecuteCommand(sql, para);

即可。