1
Answer

Updating Access tables

Ian Kennedy

Ian Kennedy

15y
2.1k
1
Hi,

I am trying to edit/update fields in a single Access table using C# Express.  I have tried the following two sets of code.  Both compile and run with no reported errors.  Neither actually writes any changes to the database table.

Can anyone tell me what I'm doing wrong?

Thanks

Ian
............................................................................................
Attempt #1
............................................................................................

private void EditJob(Int32 iUID) {

    string sqlCmd = "UPDATE JobList SET ClientRef = '" + tbClientRef.Text + "' WHERE UID = '" + iUID.ToString() + "'";
    this.jobListTableAdapter.Adapter.UpdateCommand.CommandText = sqlCmd;
    iResult = this.jobListTableAdapter.Update(this.dSJobList.JobList);
    this.dSJobList.AcceptChanges();
    ....
    }

............................................................................................
Attempt #2
............................................................................................

private void EditJob(Int32 iUID) {

                this.jobListTableAdapter.Fill(this.dSJobList.JobList);
                DataRow[] drow = dSJobList.JobList.Select("UID = '" + iUID.ToString() + "'");

                foreach (DataRow dr in drow)  // Should only be one row
                {
                    dr.BeginEdit();
                    dr["ClientRef"] = tbClientRef.Text;
                    dr.EndEdit();
                    dr.AcceptChanges();
                    this.jobListTableAdapter.Fill(this.dSJobList.JobList);
                }


Answers (1)