I use Microsoft Access, unfortunately, due to higher forces and attempts to update the record without any luck.
This is the code:
private void UpdateContact(Contact contact)
{
using (OleDbConnection db = new OleDbConnection(_connString))
{
string query = "UPDATE [Contact] SET [FirstName] = @FirstName, [LastName] = @LastName, [MobileNumber] = @MobileNumber WHERE [Id] = @Id";
OleDbCommand cmd = new OleDbCommand(query, db) { CommandType = CommandType.Text };
cmd.Parameters.AddWithValue("@Id", contact.Id);
cmd.Parameters.AddWithValue("@FirstName", contact.FirstName);
cmd.Parameters.AddWithValue("@LastName", contact.LastName);
cmd.Parameters.AddWithValue("@MobileNumber", contact.MobileNumber);
db.Open();
int rowsAffected = cmd.ExecuteNonQuery();
db.Close();
}
}
Everything seems beautiful, no exceptions to the lines. It always returns 0. I checked the values ββduring debugging and its correctness, which should be preserved. Access file created using MS Access 2007, but its type is in 2002-2003.
Any idea what I'm doing wrong?
source
share