The Problem (Q-score 2, ranked #49th of 67 in the Access VBA archive)
The scenario as originally posted in 2013
I’ve created a code that updates/edits details of a/an computer/electronic product for a C# program connecting to the MS Access. Here are the codes:
OleDbCommand cmd = new OleDbCommand("UPDATE Available SET ProductType = '" + newAvailable.ProductType + "', Brand = '"+ newAvailable.Brand + "', Model = '" + newAvailable.Model + "', SerialNo = '" + newAvailable.SerialNo + "', Remarks = '" + newAvailable.Remarks + "', RAM = '" + newAvailable.RAM + "', HDD = '" + newAvailable.HDD + "', ODD = '" + newAvailable.ODD + "', VideoCard = '" + newAvailable.VideoCard + "', PS = '" + newAvailable.PS + "' WHERE AvailableID = '"+oldAvailable.AvailableID+"'", cnn);
cmd.CommandType = CommandType.Text;
cnn.Open();
cmd.ExecuteNonQuery();
cnn.Close();
AvailableID accepts Int32 values and the rest of the variables are string. The program is executable, yet the C# detected the error.
Data type mismatch in criteria expression.
What should I do?
Why community consensus is tight on this one
Across 67 Access VBA entries in the archive, the accepted answer here holds solid answer (above median) status — meaning voters are unusually aligned on the right fix.
The Verified Solution — solid answer (above median) (+10)
11-line Access VBA pattern (copy-ready)
I suspect that you’re not passing one of your parameters correct probably the AvailableID, instead try to add the parameters this way:
var cmd = new OleDbCommand
{
Connection = cnn,
CommandType = CommandType.Text,
CommandText = "UPDATE Available SET ProductType = ?, Brand = ?, Model = ?, SerialNo = ?, Remarks = ?, RAM = ?, ODD = ?, VideoCard = ?, PS = ? WHERE AvailableID = ?"
};
cmd.Parameters.Add(new OleDbParameter {Value = newAvailable.ProductType});
cmd.Parameters.Add(new OleDbParameter {Value = newAvailable.Brand});
// add the other parameters ...
As a side note, it’s not a good idea to generate queries by concatenating strings anyway you should always use parameters.
When to Use It — classic (2013–2016)
Ranked #49th in its category — specialized fit
This pattern sits in the 68% tail relative to the top answer. Reach for it when your scenario closely matches the question title; otherwise browse the Access VBA archive for a higher-consensus alternative.
What changed between 2013 and 2026
The answer is 13 years old. The Access VBA object model has been stable across Office 2013, 2016, 2019, 2021, 365, and 2024/2026 LTSC, so the pattern still compiles. Changes that might affect you: 64-bit API declarations (use PtrSafe), blocked macros in downloaded files (Mark-of-the-Web), and the shift toward Office Scripts for web-first workflows.