次のコードで、 「条件式のデータ型が一致しません」という例外が発生するエラーを確認してください。問題の原因を見つけることができないようです...
* record.Date
null 許容DateTime?
型は明示的にキャストされますDateTime
*record.Date
は、プログラム内の他の用途のために nullable として設定されます。ただし、INSERT 操作record.Date
のセットはDateTimePickerから取得されるため、このメソッドの値をnull にすることはできません。record.Date
どこ
AND (ご不明な点がある場合)
Access ファイル (デザイン ビュー) から:
ありがとうございました!
これが AddRecord メソッドです。ありがとう!
public static int AddRecord(Record record)
{
OleDbConnection connection = LABMeetingRecordsDB.GetConnection();
string insertStatement = "INSERT INTO DocumentInfo " +
"([FileName], [Date], [Subject], [Type]) " +
"VALUES (?, ?, ?, ?)";
try {
OleDbCommand insertCommand = new OleDbCommand(insertStatement, connection);
insertCommand.Parameters.AddWithValue("@FileName", record.FileName);
insertCommand.Parameters.AddWithValue("@Date", (DateTime)record.Date);
insertCommand.Parameters.AddWithValue("@Subject", record.Subject);
insertCommand.Parameters.AddWithValue("@Type", record.getDBType());
connection.Open();
insertCommand.ExecuteNonQuery();
string selectStatement = "SELECT IDENT_CURRENT('DocumentInfo') FROM DocumentInfo";
OleDbCommand selectCommand = new OleDbCommand(selectStatement, connection);
int recordID = Convert.ToInt32(selectCommand.ExecuteScalar());
AddCategory(connection, recordID, record.Category);
return recordID;
} catch (OleDbException ex) {
throw ex;
} finally {
connection.Close();
}
}