views:

12

answers:

1

Hi there, I have the insert working fine with my sqlce 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.AddWithValue("@PIN", em.ServerData.PIN);
                            com.ExecuteNonQuery();
                        }

                    }

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

A: 

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"; 
Mitch Wheat
Thanks Mitch a little closer.There was an error parsing the query. [ Token line number = 1,Token line offset = 173,Token in error = SalesAssistantID ]}
Sorry my fault I was missing a space between "WHERE"
updated my answer with a space for completeness!
Mitch Wheat