0

我正在尝试将来自四个文本框的数据输入到 Firebird 数据库中。每次我单击执行以下代码的按钮时,我都会得到一个“ SQL Error = -804 Count of read-write columns does not equal count of values.”我不确定这个错误是什么意思。我的代码是:

 private void button1_Click(object sender, EventArgs e)
        {
                string ConnectionString = "User ID=sysdba;Password=masterkey;" +
                "Database=localhost:G:\\nael.FDB; " +
                "DataSource=localhost;Charset=NONE;";

                FbConnection addDetailsConnection = new FbConnection(ConnectionString);
                addDetailsConnection.Open();

                FbTransaction addDetailsTransaction =
                              addDetailsConnection.BeginTransaction();

                string SQLCommandText = " INSERT into Invoice_Name Values" +
                                        "('" + textBox1.Text + "',' "
                                             + textBox2.Text + "',' "
                                             + int.Parse(textBox3.Text) + "',' "
                                             + textBox4.Text + "',' "
                                             + "')";

                FbCommand addDetailsCommand = new FbCommand(SQLCommandText,
                          addDetailsConnection, addDetailsTransaction);
                addDetailsCommand.ExecuteNonQuery();
                addDetailsTransaction.Commit();
                MessageBox.Show(" Details Added");
        }
4

1 回答 1

2

我敢打赌,您的某个TextBox.Text值中有一个逗号...否则:您是否检查过您是否指定了正确数量的列?

基本上,SQL 引擎抱怨你给了它一个参数列表,它正试图将这些参数填充到 table 中Invoice_Name,除了该表中的列计数值太多。尝试打印SQLCommandText到输出窗口 ( Debug.WriteLine(SQLCommandText)),看看是否是您所期望的...

你也不应该这样做......在这里查看这篇文章:Inserting into DB with parameters safe from SQL injection?

于 2013-06-12T09:36:10.947 回答