我正在尝试将四个文本框中的数据输入到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");
}
答案 0 :(得分:2)
我打赌你的TextBox.Text
个值中有一个逗号...否则:您是否检查过是否指定了正确数量的列?
基本上,SQL引擎抱怨你给它一个参数列表,它正试图将这些参数填入表Invoice_Name
,除了它有太多的值列表中的列数。尝试将SQLCommandText
打印到输出窗口(Debug.WriteLine(SQLCommandText)
),看看是否符合预期...
您也不应该这样做...请在此处查看此帖:Inserting into DB with parameters safe from SQL injection?