PC Review


Reply
Thread Tools Rate Thread

DataAdapter.AcceptChangesDuringUpdate not working

 
 
=?Utf-8?B?R2Vvcmdl?=
Guest
Posts: n/a
 
      16th Jun 2006

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
 
Reply With Quote
 
 
 
 
Marina Levit [MVP]
Guest
Posts: n/a
 
      16th Jun 2006
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



 
Reply With Quote
 
=?Utf-8?B?R2Vvcmdl?=
Guest
Posts: n/a
 
      16th Jun 2006
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

>
>
>

 
Reply With Quote
 
Marina Levit [MVP]
Guest
Posts: n/a
 
      16th Jun 2006
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

>>
>>
>>



 
Reply With Quote
 
=?Utf-8?B?R2Vvcmdl?=
Guest
Posts: n/a
 
      16th Jun 2006
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
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
Kevin Yu [MSFT]
Guest
Posts: n/a
 
      19th Jun 2006
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.)

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
AcceptChangesDuringUpdate Too Literal? jlspublic@hotmail.com Microsoft ADO .NET 1 17th Oct 2006 09:36 PM
DataAdapter not working in VS2005 =?Utf-8?B?TXVydGh5?= Microsoft Dot NET Compact Framework 3 3rd Aug 2006 08:21 PM
DataAdapter.Update not working Craig Hoy Microsoft ADO .NET 4 9th Feb 2006 02:20 AM
DataAdapter.Update is not working Ashish Sheth Microsoft ADO .NET 8 15th Sep 2004 01:04 PM
DataAdapter update - not working Shahar Microsoft C# .NET 1 10th Aug 2003 03:02 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:28 AM.