PC Review


Reply
Thread Tools Rate Thread

Can't understand the purpose of AcceptChanges on a DataView

 
 
Johann Blake
Guest
Posts: n/a
 
      27th Sep 2005
I'm not sure that I entirely understand the purpose of the
AcceptChanges methon in a DataView. I added a new record to a DataView
and noticed that its RowState indicated it as being "Added". If I
execute the Update method on an adapter for the table that the DataView
is based on, the new record will indeed be written to the database. But
if I call AcceptChanges prior to executing the Update method, the
RowState for the new record is changed to "Unchanged" and the new
record is not stored in the database when the Update method is
executed.

I don't get it. The .NET documentation clearly states the following:

"Calling AcceptChanges on the DataSet, DataTable, or DataRow will cause
all Original values for a DataRow to be overwritten with the Current
values for the DataRow"

and...

"After verifying the accuracy of changes made to data in a DataTable,
you can accept the changes using the AcceptChanges method of the
DataRow, DataTable, or DataSet, which will set the Current row values
to be the Original values and will set the RowState property to
Unchanged"

This is exactly what it is doing but what's the logic for not allowing
this newly added record to be stored in the database. Just because the
RowState now indicates "Unchanged", this should mean that the new
record should not be stored?? What then is the point of AcceptChanges
if you can't store the changes you've accepted?

Thanks for your response.
Johann Blake

 
Reply With Quote
 
 
 
 
=?Utf-8?B?SXZhbiBXb25n?=
Guest
Posts: n/a
 
      27th Sep 2005
The AcceptChanges method of DataView should only be used when you "accept the
changes" and you don't wanna update the database or in other word, only
update the presentation layer. (which means AcceptChanges method is a very
easy way to set the RowState of each DataRow object to unchange, so you don't
have to set the RowState in each DataRow object)

when the update method of the DataAdapter is called, it will called the
AcceptChanges method after it update the database.

"Johann Blake" wrote:

> I'm not sure that I entirely understand the purpose of the
> AcceptChanges methon in a DataView. I added a new record to a DataView
> and noticed that its RowState indicated it as being "Added". If I
> execute the Update method on an adapter for the table that the DataView
> is based on, the new record will indeed be written to the database. But
> if I call AcceptChanges prior to executing the Update method, the
> RowState for the new record is changed to "Unchanged" and the new
> record is not stored in the database when the Update method is
> executed.
>
> I don't get it. The .NET documentation clearly states the following:
>
> "Calling AcceptChanges on the DataSet, DataTable, or DataRow will cause
> all Original values for a DataRow to be overwritten with the Current
> values for the DataRow"
>
> and...
>
> "After verifying the accuracy of changes made to data in a DataTable,
> you can accept the changes using the AcceptChanges method of the
> DataRow, DataTable, or DataSet, which will set the Current row values
> to be the Original values and will set the RowState property to
> Unchanged"


The documentation clearly states that after AcceptChanges method is called
it will ONLY change the RowState to "Unchanged" WITHOUT update the database.

>
> This is exactly what it is doing but what's the logic for not allowing
> this newly added record to be stored in the database. Just because the
> RowState now indicates "Unchanged", this should mean that the new
> record should not be stored?? What then is the point of AcceptChanges
> if you can't store the changes you've accepted?
>
> Thanks for your response.
> Johann Blake
>
>


Hope it helps
Ivan Wong
 
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
Sorted DataView, but unsorted datalist when bound to the dataview CodeMonkey Microsoft ASP .NET 1 4th Feb 2011 10:55 AM
What is the purpose of AcceptChanges? Jerry H. Microsoft ADO .NET 9 27th Feb 2007 02:14 PM
Trying to understand the purpose of interfaces jm Microsoft C# .NET 27 8th Nov 2006 05:55 PM
Is there an easy way to copy a DataView (or even the DataGrid showing the DataView) to the Clipboard? Kevin Brown Microsoft Dot NET 4 5th Jan 2005 09:01 PM
AcceptChanges does nothing ?? Dmitry Sazonov Microsoft ADO .NET 1 21st Jul 2003 11:15 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:56 AM.