我在将记录插入我的访问数据库时遇到了很大的困难。我已经在访问中尝试了查询,它插入得很好。我还尝试了查询生成器中的查询,它也可以工作,但是如果我运行此代码,它声称已将记录插入数据库,但是当我检查数据库时没有新记录的迹象。
oleDbCommandCreateAppointment.Parameters["appointmentDate"].Value = "06/04/2012";
oleDbCommandCreateAppointment.Parameters["timeSlotID"].Value ="21";
oleDbCommandCreateAppointment.Parameters["startTime"].Value = "09:00";
oleDbCommandCreateAppointment.Parameters["employeeID"].Value ="1";
oleDbCommandCreateAppointment.Parameters["clientID"].Value ="1";
oleDbCommandCreateAppointment.Parameters["assistantID"].Value ="1";
oleDbCommandCreateAppointment.Parameters["appointmentType"].Value = "Quote";
oleDbCommandCreateAppointment.Parameters["appointmentFlag"].Value = "Booked";
try
{
oleDbConnection.Open();
int rows = oleDbCommandCreateAppointment.ExecuteNonQuery();
MessageBox.Show("Rows inserted " + rows.ToString());
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
oleDbConnection.Close();
}
SQL 命令
INSERT INTO tblAppointments
(appointmentDate, timeSlotID, startTime, employeeID, clientID, assistantID, appointmentType, appointmentFlag)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
非常感谢