错误:command.ExecuteNonQuery()中INSERT INTO语句中的语法错误

时间:2015-10-21 11:49:05

标签: c# ms-access

我在以下行Syntax error in INSERT INTO statement

中收到错误command.ExecuteNonQuery(); 顺便说一下,我已经发了一些相似的帖子,我试图解决我的问题,但我无法这样做。

我的数据库是MS Access

任何帮助都会很棒!

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();  

            }

        }

1 个答案:

答案 0 :(得分:0)

试试这个。也许它可以帮助

密码是保留关键字

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

试试这个

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