469,602 Members | 1,979 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,602 developers. It's quick & easy.

DataAdapter.AcceptChangesDuringUpdate not working


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(jobListDataA dapter);

jobListDataTable = new System.Data.DataTable("Job List
Access DataTable");
jobListDataAdapter.AcceptChangesDuringFill = true;
jobListDataAdapter.AcceptChangesDuringUpdate = true;

jobListDataAdapter.Fill(jobListDataTable);
....
}

Thanks,

--
George
Jun 16 '06 #1
5 4780
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" <wa**@nospam.nospam> wrote in message
news:E0**********************************@microsof t.com...

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(jobListDataA dapter);

jobListDataTable = new System.Data.DataTable("Job List
Access DataTable");
jobListDataAdapter.AcceptChangesDuringFill = true;
jobListDataAdapter.AcceptChangesDuringUpdate = true;

jobListDataAdapter.Fill(jobListDataTable);
...
}

Thanks,

--
George

Jun 16 '06 #2
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" <wa**@nospam.nospam> wrote in message
news:E0**********************************@microsof t.com...

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(jobListDataA dapter);

jobListDataTable = new System.Data.DataTable("Job List
Access DataTable");
jobListDataAdapter.AcceptChangesDuringFill = true;
jobListDataAdapter.AcceptChangesDuringUpdate = true;

jobListDataAdapter.Fill(jobListDataTable);
...
}

Thanks,

--
George


Jun 16 '06 #3
Which table are you checking for the row state - jobListDataAdapter or
oChangeDataTable?

"George" <wa**@nospam.nospam> wrote in message
news:14**********************************@microsof t.com...
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" <wa**@nospam.nospam> wrote in message
news:E0**********************************@microsof t.com...
>
> 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(jobListDataA dapter);
>
> jobListDataTable = new System.Data.DataTable("Job List
> Access DataTable");
> jobListDataAdapter.AcceptChangesDuringFill = true;
> jobListDataAdapter.AcceptChangesDuringUpdate = true;
>
> jobListDataAdapter.Fill(jobListDataTable);
> ...
> }
>
>
>
> Thanks,
>
> --
> George


Jun 16 '06 #4
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" <wa**@nospam.nospam> wrote in message
news:14**********************************@microsof t.com...
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" <wa**@nospam.nospam> wrote in message
news:E0**********************************@microsof t.com...
>
> 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(jobListDataA dapter);
>
> jobListDataTable = new System.Data.DataTable("Job List
> Access DataTable");
> jobListDataAdapter.AcceptChangesDuringFill = true;
> jobListDataAdapter.AcceptChangesDuringUpdate = true;
>
> jobListDataAdapter.Fill(jobListDataTable);
> ...
> }
>
>
>
> Thanks,
>
> --
> George


Jun 16 '06 #5
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.)

Jun 19 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

20 posts views Thread by TJ Doherty | last post: by
6 posts views Thread by Geoff Pennington | last post: by
8 posts views Thread by Zorpiedoman | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.