我正在使用以下代码更新用户信息,但出现错误。谁能指出我出了什么问题。我正在为 Web 服务编写此代码。
public string UpdateUser(int uID, string fName,
string lName, string password, string emailAddress)
{
// Create connection object
int ix = 0;
string rTurn = "";
OleDbConnection oleConn = new OleDbConnection(connString);
try
{
oleConn.Open();
string sql = "UPDATE [User] SET [fName]=@fName, [lName]=@lName, [password]=@password, [emailAddress]=@emailAddress" + "WHERE [ID]=@uID";
OleDbCommand oleComm = new OleDbCommand(sql, oleConn);
oleComm.Parameters.Add("@fName", OleDbType.Char).Value = fName;
oleComm.Parameters.Add("@lName", OleDbType.Char).Value = lName;
oleComm.Parameters.Add("@password", OleDbType.Char).Value = password;
oleComm.Parameters.Add("@emailAddress", OleDbType.Char).Value = emailAddress;
oleComm.Parameters.Add("@uID", OleDbType.Integer).Value = uID;
ix = oleComm.ExecuteNonQuery();
if (ix > 0)
rTurn = "User Updated";
else
rTurn = "Update Failed";
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
rTurn = ex.ToString();
}
finally
{
oleConn.Close();
}
return rTurn;
}
错误 *当我尝试更新用户时出现以下错误。*
<string>
System.Data.OleDb.OleDbException: Syntax error (missing operator) in query expression '@emailAddressWHERE [ID]=@uID'.
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr)
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
at System.Data.OleDb.OleDbCommand.ExecuteNonQuery()
at UserManagement.UserRegistration.UpdateUser(Int32 uID, String fName, String lName, String password, String emailAddress) in C:\Users\smartamrit\Desktop\SystemSoftware\UserManagement\UserRegistration.asmx.cs:line 97
</string>