0

我有一个问题,当我运行我的代码时,会发生错误,即“” System.Data.OleDb.OleDbException:标准表达式中的数据类型不匹配。“”。数据类型是数字。

请就此向我提出建议。

"代码

 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,Designation,Grade,Team,Location,EmployementType,HolidayGroup) values ('" + txt_empname.Text + "','" + txt_code.Text + "', '"+ 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_holigroup.SelectedItem)+"')";
        OleDbCommand cmd = new OleDbCommand(query, conn);
        cmd.ExecuteNonQuery();
        conn.Close();
        BindGridData();
    }

“谢谢”

4

1 回答 1

1

You put strings as values in your insert startement and some of your db values are not of type string. That is causing the error.

Look at your table definition and convert the parameters of your insert statement to the correct types.

于 2012-04-27T05:39:59.993 回答