Hi Marina,
I figured out what I did wrong. I guess the reason is related to your
question as well.
I have called DataAdapter.Update(oChangeDataTable). I thought this will be
more efficient since it is a smaller or equal size table. However, the
AcceptChangesDuringUpdate flag is causing oChangeDataTable.AccpetChanges() to
be called, while jobListDataTable's changes have not been accepted.
Now I changed my call to DataAdapter.Update(jobListDataTable) and it works
as I desired. I came across this while I was review my codes and realized
that DataAdapter does contain any reference to a particular DataTable. the
DataTable is passed into method's parameter.
Thanks for your help
--
George
"Marina Levit [MVP]" wrote:
> Which table are you checking for the row state - jobListDataAdapter or
> oChangeDataTable?
>
> "George" <(E-Mail Removed)> wrote in message
> news:14570085-0C56-4DA5-9B68-(E-Mail Removed)...
> > The snippet only demonstrate how I setup AcceptChangesDuringUpdate.
> >
> > Eventually, at some other location I would have call
> >
> > {
> > ...
> > oChangeDataTable = this.jobListDataTable.GetChanges();
> > if (oChangeDataTable != null)
> > {
> > this.JobListDataAdapter.Update(oChangeDataTable);
> >
> > foreach (System.Data.DataRow oDataRow in
> > oChangeDataTable.Rows)
> > {
> > if (oDataRow[JobDataGridViewColumnId] ==
> > System.DBNull.Value)
> > {
> > this.jobListDataTable.Clear();
> >
> > this.jobListDataAdapter.Fill(this.jobListDataTable);
> > break;
> > }
> > }
> >
> > jobListDataTable.AcceptChanges();
> >
> > ...
> > }
> >
> > After Update(), the RowState of changed rows seem to be updated to
> > "unchanged" from "Added", "Deleted"... and what not.
> >
> > However, without specifically calling DataTable.AcceptChanges(), the next
> > call to DataTable.GetChanges() still returns a table of changed rows.
> >
> > Any ideas?
> >
> >
> >
> > --
> > George
> >
> >
> > "Marina Levit [MVP]" wrote:
> >
> >> You are only getting data into the table in this example. You are not
> >> updating the database, so that property would not be relevant.
> >>
> >> "George" <(E-Mail Removed)> wrote in message
> >> news:E0A21F96-806C-4B37-86F0-(E-Mail Removed)...
> >> >
> >> > I have set DataAdapter.AcceptChangesDuringUpdate = true;
> >> >
> >> > However, I find that I still need to call AcceptChanges on the
> >> > associated
> >> > DataTable,
> >> >
> >> > DataTable.AcceptChanges();
> >> >
> >> > Has anyone encountered that? Am I not setting this field properly?
> >> >
> >> > The following are some of the snippets of the codes which may help
> >> > explain
> >> > what I was doing,
> >> >
> >> >
> >> > //Setting DataAdapter.AcceptChangesDuringUpdate
> >> > {
> >> > ...
> >> >
> >> > jobListDataAdapter = new
> >> > System.Data.OleDb.OleDbDataAdapter(commandString, oOleDbConn);
> >> >
> >> > oOleDbCommandBuilder = new
> >> > System.Data.OleDb.OleDbCommandBuilder(jobListDataAdapter);
> >> >
> >> > jobListDataTable = new System.Data.DataTable("Job List
> >> > Access DataTable");
> >> > jobListDataAdapter.AcceptChangesDuringFill = true;
> >> > jobListDataAdapter.AcceptChangesDuringUpdate = true;
> >> >
> >> > jobListDataAdapter.Fill(jobListDataTable);
> >> > ...
> >> > }
> >> >
> >> >
> >> >
> >> > Thanks,
> >> >
> >> > --
> >> > George
> >>
> >>
> >>
>
>
>
|