查询值和目标字段的数量不相同 [英] Number of query values and destination fields are not the same
问题描述
我有一个问题,当我运行我的代码时,会发生错误,即"查询值和目标字段的数量不相同."
I have a problem, when i m run my code then error is occured that "Number of query values and destination fields are not the same."
plz为此建议我.
"代码"
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 Employees (EmployeeName,EmployeeCode,DeviceCode,Company,Department,Designation,Grade,Team,Location,EmploymentType,Category,HolidayGroup,ShiftGroup,ShiftRoster,Dateofjoining,Dateofconfirmation,Status,DateofResigning,Sex) values ('" + txt_empname.Text + "','" + txt_code.Text + "', '" + txt_dcode.Text + "', '" + Convert.ToString(dp_company.SelectedItem)+ "', '" + Convert.ToString(dp_department.SelectedItem) + "', '"+Convert.ToString(dp_designation.SelectedItem)+"', '"+Convert.ToString(dp_grade.SelectedItem)+"', '"+Convert.ToString(dp_team.SelectedItem)+"', '"+Convert.ToString(dp_location.SelectedItem)+"', '"+Convert.ToString(dp_emptype.SelectedItem)+"', '"+Convert.ToString(dp_category.SelectedItem)+"', '"+Convert.ToString(dp_holigroup.SelectedItem)+"', '"+Convert.ToString(dp_shiftgroup.SelectedItem)+"', '"+Convert.ToString(dp_shiftroster.SelectedItem)+"', '"+Convert.ToString(dp_day.SelectedItem)+"', '"+Convert.ToString(dp_month.SelectedItem)+"', '"+Convert.ToString(dp_year.SelectedItem)+"', '"+Convert.ToString(dp_cday.SelectedItem)+"', '"+Convert.ToString(dp_cmonth.SelectedItem)+"', '"+Convert.ToString(dp_cyear.SelectedItem)+"', '"+Convert.ToString(dp_status.SelectedItem)+"', '"+Convert.ToString(dp_rday.SelectedItem)+"', '"+Convert.ToString(dp_rmonth.SelectedItem)+"', '"+Convert.ToString(dp_ryear.SelectedItem)+"', '"+Convert.ToString(rdbtn_male.Checked)+"', '"+Convert.ToString(rdbtn_female.Checked)+"')";
OleDbCommand cmd = new OleDbCommand(query, conn);
cmd.ExecuteNonQuery();
conn.Close();
BindGridData();
}
谢谢"
推荐答案
此查询的问题是,您告诉查询要插入19个插入参数(EmployeeName,EmployeeCode,DeviceCode,Company,Department,Designation,Grade,Team ,位置,就业类型,类别,假日组,ShiftGroup,ShiftRoster,加入日期,确认日期,状态,辞职日期,性别)
The problem with this query is that you are telling the query to expect 19 insert parameters(EmployeeName,EmployeeCode,DeviceCode,Company,Department,Designation,Grade,Team,Location,EmploymentType,Category,HolidayGroup,ShiftGroup,ShiftRoster,Dateofjoining,Dateofconfirmation,Status,DateofResigning,Sex)
但是您尝试插入的内容不止于此(26)-如果您计算要插入的值,您会发现它们不匹配.
But you are trying to insert more than that (26) - if you count the values that you're trying to insert you'll see that they don't match up.
因此,您可以删除查询后半部分的多余值,也可以添加其他插入参数.例如,您似乎试图多次插入年",月"和天"的值,但是您只有一个日期字段.您应该将它们串联在一起并转换为日期,以使插入件正常工作.
So you can either remove the extra values in the latter half of your query, or add additional insert parameters. For example, you seem to be trying to insert a value for "year", "month", and "day" several times, yet you only have one date field. You should concatenate those together and convert to a date in order to get the insert working correctly.
这篇关于查询值和目标字段的数量不相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!