OleDb does not support named parameters. I guess this is what causes errors. Instead, use in a SQL query ? instead of the name param and make sure the order of the added parameters matches the order that they display in the request. So:
using(OleDbCommand cmd = new OleDbCommand("SELECT UserID FROM tblUser WHERE Username=? AND Password = ?", conn)) { cmd.Parameters.AddWithValue("@user", user); cmd.Parameters.AddWithValue("@pass", pass); int UserID = (int)cmd.ExecuteScalar(); return UserID < 0 ? -1 : UserID; }
source share