Would you please kindly check the following code for errors that give me a 'Data type mismatch in criteria expression' exception? I just can't seem to find the source of the problem...
*record.Date
of nullable DateTime?
type is explicitly casted to DateTime
*record.Date
is set as nullable for other uses in the program. But the record.Date
set for the INSERT operation is retrieved from a DateTimePicker, so a record.Date
value for this method should never be null.
WHERE
AND (in case you're wondering)
From my Access file (Design View):
Thank you!
Here's the AddRecord method. Thanks!
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();
}
}
C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...
C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.
Full form of C is “COMPILE”.
Because a and b and c , so it's name is C. C came out of Ken Thompson's Unix project at AT&T. He originally wrote Unix in assembly language. He wrote a language in assembly called B that ran on Unix, and was a subset of an existing language called BCPL.
So...[PROBLEM SOLVED] :D
From HERE I learnt that
The problem of the mismatch in criteria expression is due to the OleDbType assigned to the parameter used to represent the DateTime.Now value when you call AddWithValue.
The OleDbType choosen by AddWithValue is DBTimeStamp, but Access wants a OleDbType.Date.
Meaning that the convenient AddWithValue
pulled a fast one on me...
Thank you @LarsTech and @DJKraze for helping me out despite the confusion of the presentation!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With