pedro jorge
pedro jorge

Reputation: 13

Error: Syntax error in INSERT INTO statement in command.ExecuteNonQuery()

I get the error Syntax error in INSERT INTO statement in following line command.ExecuteNonQuery();

BTW, I already red some similar posts and I tried to fix my problem but I could not able to do so.

My database is MS Access.

Any help will be great!

private void btn_register_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txt_name.Text) || string.IsNullOrEmpty(txt_family.Text))
            {
                MessageBox.Show("Some information is missed");
            }
            else
            {
                this.Hide();
                connection.Open();
                OleDbCommand command = new OleDbCommand();
                command.Connection = connection;
                command.CommandText = " insert into Login (FirstName,FamilyName,UserName,PassWord,RepeatPassword,Email,MaxTime,LearningStyle) values ('" + txt_name.Text + "','" + txt_family.Text + "','" + txt_username.Text + "','" + txt_password.Text + "','" + txt_repeat.Text + "','" + txt_mail.Text + "','" + UpDownTime.Value + "','" + UpDownLearningStyle.Value + "')";
                command.ExecuteNonQuery();
                MessageBox.Show("Your Registeration was successfull !");
                connection.Close();
                Login F1 = new Login();
                F1.Show();  

            }

        }

Upvotes: 1

Views: 1387

Answers (1)

jLaw
jLaw

Reputation: 302

Try this. maybe it could help

Password is a reserved keyword

command.CommandText = " insert into Login (FirstName,FamilyName,UserName,PassWord,RepeatPassword,Email,....

try this

command.CommandText = " insert into Login (FirstName,FamilyName,UserName,[PassWord],RepeatPassword,Email,.....

Upvotes: 1

Related Questions