尝试更新SQL Server CE失败

时间:2010-10-23 04:20:12

标签: c# sql-server-ce

我的插件在我的SQL Server CE数据库中工作正常但是我很难更新。

任何人都可以看到我正在尝试的是什么错误

using (SqlCeConnection con = new SqlCeConnection(ConfigurationManager.ConnectionStrings["MyConnection"].ConnectionString))
{
    con.Open();
    // Insert into the SqlCe table. ExecuteNonQuery is best for inserts.
    string sql = "UPDATE SalesAssistant SET "
          + "(Name=@Name,IsEnabled=@IsEnabled,Role=@Role,LastModifiedDate=@LastModifiedDate,IsAdministrator=@IsAdministrator,PIN=@PIN,IsDeleted=@IsDeleted)" +
          "WHERE SalesAssistantID=@SalesAssistantID";

    using (SqlCeCommand com = new SqlCeCommand(sql, con))
    {
        com.Parameters.AddWithValue("@SalesAssistantID", em.ServerData.EmployeeID);
        com.Parameters.AddWithValue("@Name", em.ServerData.EmployeeName);
        com.Parameters.AddWithValue("@IsEnabled", em.ServerData.IsEnabled);
        com.Parameters.AddWithValue("@LastModifiedDate", em.ServerData.LastModifiedDate);
        com.Parameters.AddWithValue("@IsAdministrator", em.ServerData.IsAdministrator);
        com.Parameters.AddWithValue("@IsDeleted", em.ServerData.IsDeleted);
        com.Parameters.AddWithValue("@Role", em.ServerData.Role);
        com.Parameters.AddWithValue("@PIN", em.ServerData.PIN);
        com.ExecuteNonQuery();
    }
}

我收到以下错误:

  

解析查询时出错。 [令牌行号= 1,令牌行偏移= 27,令牌错误=(]

1 个答案:

答案 0 :(得分:2)

删除SET列表周围的括号,即

  string sql = "UPDATE SalesAssistant SET " 
+ "Name=@Name,IsEnabled=@IsEnabled,Role=@Role,LastModifiedDate=@LastModifiedDate,IsAdministrator=@IsAdministrator,PIN=@PIN,IsDeleted=@IsDeleted" + 
 " WHERE SalesAssistantID=@SalesAssistantID";