にレコードOleDbParameter
を作成するためOleDbCommand
に使用しています。しかし、ステートメントを実行しているときに構文エラーが発生します。クエリの正常な実行を妨げている原因を誰かが確認できれば、非常に役立ちます。INSERT
MS Access
これは私のコードです:
string query = "INSERT INTO Customer (customerID, date, time, telephone, fax,"
+ "name, sourceAddress, destAddress, via1, via2, via3,"
+ "priority, ourReference) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
OleDbCommand oleDbCommand = new OleDbCommand(query, oleDbConnection);
OleDbParameter customerID = new OleDbParameter();
OleDbParameter date = new OleDbParameter();
OleDbParameter time = new OleDbParameter();
OleDbParameter telephone = new OleDbParameter();
OleDbParameter fax = new OleDbParameter();
OleDbParameter name = new OleDbParameter();
OleDbParameter sourceAddress = new OleDbParameter();
OleDbParameter destAddress = new OleDbParameter();
OleDbParameter via1 = new OleDbParameter();
OleDbParameter via2 = new OleDbParameter();
OleDbParameter via3 = new OleDbParameter();
OleDbParameter priority = new OleDbParameter();
OleDbParameter ourReference = new OleDbParameter();
oleDbCommand.Parameters.Add(customerID);
oleDbCommand.Parameters.Add(date);
oleDbCommand.Parameters.Add(time);
oleDbCommand.Parameters.Add(telephone);
oleDbCommand.Parameters.Add(fax);
oleDbCommand.Parameters.Add(name);
oleDbCommand.Parameters.Add(sourceAddress);
oleDbCommand.Parameters.Add(destAddress);
oleDbCommand.Parameters.Add(via1);
oleDbCommand.Parameters.Add(via2);
oleDbCommand.Parameters.Add(via3);
oleDbCommand.Parameters.Add(priority);
oleDbCommand.Parameters.Add(ourReference);
customerID.Value = 4;
date.Value = "01/01/01";
time.Value = "01:01:01";
telephone.Value = 01010101;
fax.Value = 01010101;
name.Value = "test 4";
sourceAddress.Value = "test 4 source address";
destAddress.Value = "test 4 dest address";
via1.Value = "test 4 via 1";
via2.Value = "test 4 via 2";
via3.Value = "test 4 via 3";
priority.Value = 1;
ourReference.Value = "test 4 ref";
MessageBox.Show(oleDbCommand.CommandText.ToString());
OleDbDataAdapter oleDbDataAdapter = new OleDbDataAdapter(oleDbCommand);
oleDbCommand.CommandText = query;
oleDbConnection.Open();
oleDbCommand.ExecuteNonQuery();