I've been stuck on this problem for a couple of hours now and would really appreciate any help.
What I'm trying to do: Update a 2003 MS Access Database using OleDb.
What happens when I execute the code: No error messages, but database is not updated at all. 0 Rows Affected.
Programming Language: C#
Extra Information:
(1) var_workid is an int, and is the primary key of my table.
(2) f2_sub and f2_field are Comboboxes.
(3) f2_date is a DateTimePicker.
(4) f2_details, f2_pacq, f2_daily, f2_area are all TextBoxes.
(5) My connection works, I can do statements such as SELECT ... FROM ... WHERE with no problem.
(6) .NET2.0
In MS Access.
work_id, account_code, field_id, pacquiao, daily, area are all Numbers.
details is Text.
date_done is DateTime
private void btn_update_Click(object sender, EventArgs e)
{
string update_query;
OleDbCommand SQLCommand = new OleDbCommand();
update_query = "UPDATE [work_done] SET [account_code]= @AccountCode, [field_id] = @FieldID, [details] = @Details, [pacquiao] = @Pacquiao,[daily] = @Daily, [date_done] = @DateDone, [area] = @Area WHERE [work_id] = @WorkID;";
SQLCommand.CommandText = update_query;
SQLCommand.Connection = database;
//Parameters
SQLCommand.Parameters.AddWithValue("@AccountCode", f2_sub.SelectedValue.ToString());
SQLCommand.Parameters.AddWithValue("@FieldID", f2_field.SelectedValue.ToString());
SQLCommand.Parameters.AddWithValue("@Details", f2_details.Text);
SQLCommand.Parameters.AddWithValue("@Pacquiao", f2_pacq.Text);
SQLCommand.Parameters.AddWithValue("@Daily", f2_daily.Text);
SQLCommand.Parameters.AddWithValue("@DateDone", f2_date.Value.ToString());
SQLCommand.Parameters.AddWithValue("@Area", f2_area.Text);
SQLCommand.Parameters.AddWithValue("@WorkID", var_workid);
SQLCommand.CommandText = update_query;
SQLCommand.Connection = database;
//string message = "";
//for (int i = 0; i < SQLCommand.Parameters.Count; i++)
//{
// message += SQLCommand.Parameters[i].Value.ToString() + "\n";
//}
//MessageBox.Show(message);
int response = SQLCommand.ExecuteNonQuery();
MessageBox.Show(response + " Update successful!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.ParentForm.refresh();
Close();
}