C# INSERT ERROR MYSQL Server Version For the Right Syntax to user near

461 Views Asked by At

This is my error

You have an error in your SQL syntax; check the manual that corresponds to your MySql server version for the right syntax to use near 'Key) VALUES ('biaprot','4E0658D00F47D86D19A0E792E...' at line 1.

My code :

private bool validate_register(string user, string pass)
    {
        db_connection();
        MySqlCommand cmd = new MySqlCommand();
        cmd.CommandText = "INSERT INTO accounts (Username,Key) VALUES (@user,@pass)";
        cmd.Parameters.AddWithValue("@user", user);
        cmd.Parameters.AddWithValue("@pass", pass);
        cmd.Connection = connect;
        MySqlDataReader login = cmd.ExecuteReader();
        if (login.Read())
        {
            connect.Close();
            return true;
        }
        else
        {
            connect.Close();
            return false;
        }
    }
private void button1_Click(object sender, EventArgs e)
    {
        string user = textBox1.Text;
        string pass = GetWP(textBox3.Text);
        string pass2 = GetWP(textBox4.Text);

I use WhirlPool Hash to Encoded my password . Pls help me , thanks you

1

There are 1 best solutions below

1
On

key is a mysql keyword, to use it as a column name you have to quote it in backticks

cmd.CommandText = "INSERT INTO accounts (Username,`Key`) VALUES (@user,@pass)";