我编写了这段代码来将数据插入到我的 Microsoft Access 数据库中,但它失败并引发了这个错误:
INSERT INTO 语句中的语法错误。
这是我的代码:
// Open the connection to the database.
connection.Open();
OleDbCommand dbcmd = new OleDbCommand();
dbcmd.Connection = connection;
// Inserting Data.
dbcmd.CommandText = "insert into ConveyanceBill1 (empname, from) values('" + txtEmployee.Text + "','" + txtFrom.Text + "')";
dbcmd.ExecuteNonQuery();
MessageBox.Show("Sucessfully Added!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
connection.Close();
但如果我改变这一行:
// Inserting Data.
dbcmd.CommandText = "insert into ConveyanceBill1 (empname, from) values('" + txtEmployee.Text + "','" + txtFrom.Text + "')";
到这条线:
// Inserting Data.
dbcmd.CommandText = "insert into ConveyanceBill1 (empname, designation) values('" + txtEmployee.Text + "','" + txtDesignation.Text + "')";
它完美无缺。我找不到它为什么不工作的原因。这是我在设计视图中的数据库表:
我尝试了很多,但我仍然不明白为什么它不起作用。