For Microsoft Access, options are position-based and unnamed, should you use ?
as a placeholder, although the code will work if you used the name parameters, provided that they are in the same order.
See the documentation for the OleDbCommand.Parameters Property
Notes
The OLE DB.NET provider does not support named parameters for passing parameters to an SQL statement or stored procedure called by OleDbCommand when the CommandType parameter is set to Text. In this case, you must use the question mark (?). For instance:
SELECT * FROM Customers WHERE CustomerID = ?
Therefore, the order in which OleDbParameter objects are added to the OleDbParameterCollection must directly correspond to the position of the question mark placeholder for the parameter in the command text.
Be sure to indicate the expected type of circuit in which the parameter will be used, and the length of the circuit, if applicable.
I also recommend that you always use using expressions around your instances, where the type implements IDisposable
as OleDbConnection
, so the connection always closes, even if an exception is added to the code.
Modified Code:
var connectionStringHere = @"Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + Server.MapPath("App_Data\\BookRateInitial.mdb"; using (var conn = new OleDbConnection(connectionStringHere)) using (var cmd = conn.CreateCommand()) { cmd.CommandText = "INSERT INTO bookRated ([title], [rating], [review], [frnISBN], [frnUserName]) VALUES(?, ?, ?, ?, ?)"; cmd.Parameters.Add(new OleDbParameter("?", OleDbType.VarChar, 100) { Value = title}); cmd.Parameters.Add(new OleDbParameter("?", OleDbType.Integer) { Value = rating }); cmd.Parameters.Add(new OleDbParameter("?", OleDbType.VarChar, 2000) { Value = review }); cmd.Parameters.Add(new OleDbParameter("?", OleDbType.VarChar, 60) { Value = ISBN }); cmd.Parameters.Add(new OleDbParameter("?", OleDbType.VarChar, 256) { Value = userName }); conn.Open(); var numberOfRowsInserted = cmd.ExecuteNonQuery(); }