错误查询值和目标字段的数量不同

时间:2012-05-04 07:39:37

标签: ms-access-2007

当我运行我的代码“没有YearlyLimit”时遇到问题然后它运行正常但是当我在插入查询中添加YearlyLimit时会发生错误

  

“查询值和目标字段的数量不相同。”

protected void btn_Save_Click(object sender, EventArgs e)
{
    string str = ("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:/Users/Geeta/Desktop/eTimeTrackLite1.mdb;Persist Security Info=False;");
    OleDbConnection conn = new OleDbConnection(str);
    conn.Open();
    string query = "insert into LeaveTypes (LeaveTypeFName,LeaveTypeSName,YearlyLimit,Gender) values ('" + txt_leavetypename.Text + "', '" + txt_shortname.Text + "', '" + txt_yearlimit.Text + "', '" + Convert.ToString(rdbtn_all.Checked) + "', '" + Convert.ToString(rdbtn_male.Checked) + "', '" + Convert.ToString(rdbtn_female.Checked) + "')";
    OleDbCommand cmd = new OleDbCommand(query, conn);
    cmd.ExecuteNonQuery();
    conn.Close();
    BindGridData();
}

1 个答案:

答案 0 :(得分:0)

您正试图在记录中添加太多项目

  1. LeaveTypeFName
  2. LeaveTypeSName
  3. YearlyLimit
  4. 性别
  5. 您正在尝试插入

    1. txt_leavetypename.Text
    2. txt_shortname.Text
    3. txt_yearlimit.Text
    4. Convert.ToString(rdbtn_all.Checked)
    5. Convert.ToString(rdbtn_male.Checked)
    6. Convert.ToString(rdbtn_female.Checked)
    7. 您需要检查您要进入最后一个字段的项目