public void UpdateRegistration(User userModel)
{
using (IDbConnection connection = BaseRepository.OpenConnection())
{
string query = "UPDATE [dbo].[TBUser] " +
"(CreatedBy, CreatedDate, ModifiedBy, ModifiedDate) VALUES " +
"(@CreatedBy, @CreatedDate, @ModifiedBy, @ModifiedDate) WHERE " +
"UserId = @UserId;";
connection.Execute(query, userModel);
}
}
运行时出现以下异常
<Message>An error has occurred.</Message>
<ExceptionMessage>Incorrect syntax near '('.</ExceptionMessage>
<ExceptionType>System.Data.SqlClient.SqlException</ExceptionType>
userModel具有与之关联的所有属性。
答案 0 :(得分:2)
语法是
UPDATE [table]
SET [field] = Value
WHERE ....
请参阅http://technet.microsoft.com/en-us/library/ms177523.aspx
所以你的查询应该是
UPDATE [dbo].[TBUser]
SET CreatedBy = @CreatedBy,
CreatedDate = @CreatedDate,
ModifiedBy = @ModifiedBy,
ModifiedDate = @ModifiedDate
WHERE UserId = @UserId;