-3

I am using this code 2 time on the same project and both tries worked, I'm wondering whats wrong on my code, my column and table is right (I copy pasted my names to be sure), and every time I try to update it, it always says syntax error on update statement

  string sql = "";
        sql = string.Format(@"UPDATE users_list
                                        SET Username='{0}',Last_name='{1}',Contact_number={2},Password='{3}',Position='{4}'
                                        WHERE ID={5}",

                                        txt_username.Text.Trim(),
                                        txt_userlastname.Text.Trim(),
                                        txt_usernumber.Text.Trim(),
                                        txt_userpassword.Text.Trim(),
                                        cbo_position.Text,
                                        txt_userid.Text.Trim());


        crudTools.ExecuteQuery(sql); //run the query
        MessageBox.Show("Records updated");
        Menu frm = new Menu();
        frm.Show(); //load form
        this.Hide(); //hide form
Janelle
  • 5
  • 4

1 Answers1

2

Looks like you're trying to update "user_list" but in the screenshot you posted in the comments the table is called "users_table".

Change the SQL to reflect this and see if that solves your issue.

Dale
  • 1,911
  • 11
  • 18
  • Already changed the table name after I noticed my name error, still getting the same error – Janelle Oct 08 '17 at 15:07
  • Can you output the value of 'sql' and paste it here. It will be much easier to spot the error once all the replacements have been done – Dale Oct 08 '17 at 15:52