UPDATE Command Parameters in C# For Access 2003 Not update

c#, ms-access

Solution

Supply the parameter values in the same order as they appear in the SQL statement.

cmd.Parameters.AddWithValue("@FirstName", txtFirstName.Text);
cmd.Parameters.AddWithValue("@LastName", txtLastName.Text);
cmd.Parameters.AddWithValue("@FamDOB", txtFamDOB.Text);
cmd.Parameters.AddWithValue("@Medical", txtMedical.Text);
cmd.Parameters.AddWithValue("@ID", txtFamID.Text);

OleDB plus MS Access doesn't care about the parameter names, only their order.

Problem

access 2003 vs 2010 c# I cannot see where I have gone wrong. There is no error but no data is being updated. I have the insert, delete and edit working but I don't know why I can't get this to work. Please can someone kindly help me here, thanks in advance... connection string ``` myCon = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:..\TempDB.mdb"); ``` Update method... ``` private void btnUpdate_Click(object sender, EventArgs e) { OleDbCommand cmd = new OleDbCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "UPDATE [Family] SET [FirstName] = ?, [LastName] = ?, [FamilyDOB] = ?, [Medical] = ? WHERE [ID] = ?"; //tried this as well //cmd.CommandText = "UPDATE [Family] SET [FirstName] = FirstName, [LastName] = @LastName, [DOB] = @StudentDOB, [Medical] = @Medical WHERE [ID] = @ID"; cmd.Parameters.AddWithValue("@ID", txtFamID.Text); cmd.Parameters.AddWithValue("@FirstName", txtFirstName.Text); cmd.Parameters.AddWithValue("@LastName", txtLastName.Text); cmd.Parameters.AddWithValue("@FamDOB", txtFamDOB.Text); cmd.Parameters.AddWithValue("@Medical", txtMedical.Text); cmd.Connection = myCon; myCon.Open(); cmd.ExecuteNonQuery(); myCon.Close(); } ```

Original source