アクセスデータベースにレコードを挿入するのが非常に困難です。私はアクセスでクエリを試してみて、それはうまく挿入します。私はまた、クエリビルダーでクエリを試してみましたが、私はこのコードを実行するとレコードがデータベースに挿入されていると主張しますが、データベースをチェックすると新しいレコードの兆候はありません。アクセスデータベースにレコードを挿入する
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 (?, ?, ?, ?, ?, ?, ?, ?)
あなたはデシベルのコマンドオブジェクトとの接続を関連付ける必要があり多くのおかげ
'?'ではなく、パラメータに名前を付けてみるとよいでしょう。 JETはあなたがしていることを理解する必要があります。つまり、 'INSERT INTO ... VALUES(@A、@B、@C)'を呼び出し、 'OleDbCommand'に名前付きパラメータ(例えば' @clientID')を追加します。 –
@ ta.spect.is OleDbCommandで名前付きパラメータを使用することはできません(私の回答を更新しました。それは私にも守られていませんでした) – pstrjds
@pstrjds JETは少し違います。 'VALUES(@A、@B、@A)'と言うことができ、 '@A'と' @B'を順に追加するだけです。 –