请您检查以下代码中是否存在“标准表达式中的数据类型不匹配”异常的错误?我似乎无法找到问题的根源......
*record.Date
可空DateTime?
类型显式转换为DateTime
*record.Date
设置为可为空,以供程序中的其他用途使用。但是INSERT 操作record.Date
的集合是从DateTimePicker中检索的,因此此方法的值永远不应为 null。record.Date
在哪里
和(如果你想知道)
从我的访问文件(设计视图):
谢谢!
这是 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();
}
}