I get a type mismatch in the expression of the criteria when inserting a new record into the access database. The application works fine on UK computers, but this error occurs on South African computers. It makes me think that this is due to the date format. However, if I change my Regional settings in southern Africa, I can not reproduce the error.
The code is as follows:
cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "INSERT INTO tblOrders " + "( UserID, AccountNumber, EmailAddress, InvoiceAddressID, DeliveryAddressID, PurchaseOrderReference, Comments, TotalPrice, [Date] )" + "VALUES (?,?,?,?,?,?,?,?,?);"; cmd.Parameters.Add(new OleDbParameter("@UserID", OleDbType.Integer)).Value = userID; cmd.Parameters.Add(new OleDbParameter("@AccountNumber", OleDbType.VarChar)).Value = accountNumber; cmd.Parameters.Add(new OleDbParameter("@EmailAddress", OleDbType.VarChar)).Value = emailAddress; cmd.Parameters.Add(new OleDbParameter("@InvoiceAddressID", OleDbType.Integer)).Value = invoiceAddressID; cmd.Parameters.Add(new OleDbParameter("@DeliveryAddressID", OleDbType.Integer)).Value = deliveryAddressID; cmd.Parameters.Add(new OleDbParameter("@PurchaseOrderReference", OleDbType.VarChar)).Value = purchaseOrderReference; cmd.Parameters.Add(new OleDbParameter("@Comments", OleDbType.VarChar)).Value = comments; cmd.Parameters.Add(new OleDbParameter("@TotalPrice", OleDbType.Decimal)).Value = totalPrice; cmd.Parameters.Add(new OleDbParameter("@Date", OleDbType.Date)).Value = date; cmd.Parameters.Add(new OleDbParameter("@ID",OleDbType.Integer)).Value = orderID; ExecuteNonQuery(cmd); // this line errors
There are a lot of similar questions in Stack, but they all seem to be building SQL strings manually, or this seems to be another reason. I double-checked the order of the parameters in the same way as in the InsertOrder request (and the code works for 99.9% of users).
UPDATE 8/8/2014
In fact, it looks like the Price parameter, which causes the problem, not the date. If I rigidly tie the price to 0, then it works fine. However, on UK and South African computers, totalPrice.ToString () now produces β350.6β when I forcefully connected the application to en-GB in web.config. So it should be that, on South African PCs, access still works at a decimal value. How can I do the same application work on both British and South African PCs? I do not understand how this can misinterpret the decimal value when using parameters.
Price is the Currency data type in the Access database.