DataAdapter.AcceptChangesDuringUpdate not working

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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,
 
You are only getting data into the table in this example. You are not
updating the database, so that property would not be relevant.
 
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?
 
Which table are you checking for the row state - jobListDataAdapter or
oChangeDataTable?

George said:
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 said:
You are only getting data into the table in this example. You are not
updating the database, so that property would not be relevant.
 
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 said:
Which table are you checking for the row state - jobListDataAdapter or
oChangeDataTable?

George said:
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 said:
You are only getting data into the table in this example. You are not
updating the database, so that property would not be relevant.


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,
 
Hi George,

Yes, this is the case. In addition, you don't need to use GetChanges to get
the difference set to update as this will not improve performance, unless
you're passing the DataSet through a web-service.

Kevin Yu
Microsoft Online Community Support

============================================================================
==========================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
============================================================================
==========================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top