How to update Access Database in C#?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Brian Connelly
    New Member
    • Jan 2011
    • 103

    How to update Access Database in C#?

    I am developing an application and all of my code reads and inserts into an mdb database file. However when I try to update, the code executes without issue, but when I check the database, the updates are not there. Here is my update code:
    Code:
                else if(isNewEntry == false)
                {
                    string query = "UPDATE hours SET hoursWorked = @p3 WHERE contactID = @p1 AND fiscalYearID = @p2";
                    cmd.CommandText = query;
                    foreach (DataGridViewRow row in dgvTime.Rows)
                    {
                       
                        id = Convert.ToInt16(row.Cells["contactID"].Value);
                        hours = Convert.ToInt16(row.Cells["hoursWorked"].Value);
                        year = yr;// Convert.ToInt16(cbFiscalYear.SelectedIndex.ToString()); 
                        cmd.Parameters.AddWithValue("@p1", id.ToString());
                        cmd.Parameters.AddWithValue("@p2", year.ToString());
                        cmd.Parameters.AddWithValue("@p3", hours.ToString());
                        cmd.Connection.Open();
                        cmd.ExecuteNonQuery();
                        cmd.Parameters.Clear();
                        cmd.Connection.Close();
                        pbEnteringData.PerformStep();
                    }
                    pbEnteringData.Value = 0;
    Any help would be greatly appreciated.
Working...