开发者

Trying to update SQL Server CE failing

开发者 https://www.devze.com 2023-01-20 21:08 出处:网络
I have the insert working fine with my SQL Server CE database however I am struggling to update. Can anyone see whats wrong with what I am trying

I have the insert working fine with my SQL Server CE database however I am struggling to update.

Can anyone see whats wrong with what I am trying

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开发者_Go百科.AddWithValue("@PIN", em.ServerData.PIN);
        com.ExecuteNonQuery();
    }
}

I get the following error:

There was an error parsing the query. [ Token line number = 1,Token line offset = 27,Token in error = ( ]


Remove the parentheses around the SET list, i.e.

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

精彩评论

暂无评论...
验证码 换一张
取 消