what does the Acceptchanges() method of the dataset do?

  • Thread starter Thread starter Juan Romero
  • Start date Start date
J

Juan Romero

Hey guys,

I would like to know what the acceptchanges() method does. I have been
trying to get a dataset to update the underlying database, and after
fighting with it FOR 2 days, I finally realized the reason why it was not
updating is because I was using this method before the update call.

Now, WHY would Microsoft programmers name this method "AcceptChanges()" If
it DOES NOT accept the changes? or it probably does something similar (I do
not know what) but IT DOES NOT DO WHAT ITS NAME SUGGESTS....

I am getting into .NET technologies now, and I just find it so hard and
ridiculouly inconsistent to work with all these controls that have methods
that don't do what they suggest.

I like Microsoft's technologies and want to become proficient at them, but
when I have to spend 2 days trying to solve some minor stupid thing because
the HELP file is virtually useless, I really consider whether I should find
another technology that saves me time and aggravation.

An example of the VS HELP FILE's usefullness:
Refresh Method: Refreshes the control.

WOW, thanks for the tip, I could not have figured that out on my own....
 
The problem is that it does accept the changes. It does exactly what the
name says.

In this case, that means that the states of all rows are changed to
unmodified. Now, if all the rows are unmodified, then there is nothing to
update of course.

The documentation clearly describes this method and exactly what it does. I
highly encourage you to not start calling methods, without knowing exactly
what they do, or if you even need them at all. Reading the documentation is
the way to do this.
 
I see what you are saying, and you make a very good point.

HOWEVER, if I accept the changes and there is nothing to update the
database in the background with, then what is the point of doing changes
to the recordset?
 
I see what you are saying, and you make a very good point.

HOWEVER, if I accept the changes and there is nothing to update the
database in the background with, then what is the point of doing
changes to the recordset?


FYI, there is no "recordset" in ADO.NET. Please refer to it as either
DataTable or DataSet as appropriate.

You are not meant to call DataSet.AcceptChanges() before calling Update()
on your DataAdapter. AcceptChanges() does have it's uses. Just because
you don't need to use it (and shouldn't in your situation) doesn't mean
the method shouldn't be there.

One of many instances it would be used is when someone is creating a new
data provider all together. They will have their own DataAdapter class
deriving from DbDataAdapter and implementing IDbDataAdapter. They will
have their own Update method and will need to use one of all of the
following:

DataSet.HasChanges
DataSet.GetChanges()
DataSet.AcceptChanges()
DataSet.Merge()

Reading the docs as Marina recomends would be a very good idea! You
should always read the help on any class member you use, that you don't
already know thouroughly.

DataSet.AcceptChanges()
"When you call AcceptChanges on the DataSet, any DataRow objects still in
edit-mode successfully end their edits. The RowState property of each
DataRow also changes; Added and Modified rows become Unchanged, and
Deleted rows are removed."

DataAdapter.Update()
"When an application calls the Update method, the DataAdapter examines
the RowState property, and executes the required INSERT, UPDATE, or
DELETE statements iteratively for each row..."

This is very clear. DataAdapter.Update() only recognized those rows that
have one of the changed RowStates, and DataSet.AcceptChanges() sets the
RowState of all rows to unchanged. So any other method that attempts to
Update a datasource after AcceptChanges has been called will not see any
changes to update!

Is there still any confusion?
 
Ok, know what acceptchanges, getchanges and all that other stuff means but
what I don't see is where does microsoft put it in there classes. example:
when you use a datagrid and call getchanges this will only work when you
click a button, place the getchanges in the datagrid leave method then
getchanges keeps empty (1/4 times it works). All the changes seems to been
accepted. Did microsoft put an acceptchanges in the lostfocus of the
datagrid??? And why does it goes perfect when clicking a button?????

Spend 4 weeks still doesn't work

Tupolev
 
Ok, know what acceptchanges, getchanges and all that other stuff means
but what I don't see is where does microsoft put it in there classes.
example: when you use a datagrid and call getchanges this will only
work when you click a button, place the getchanges in the datagrid
leave method then getchanges keeps empty (1/4 times it works). All
the changes seems to been accepted. Did microsoft put an
acceptchanges in the lostfocus of the datagrid??? And why does it goes
perfect when clicking a button?????

Spend 4 weeks still doesn't work

Tupolev

The DataGrid has never called AcceptChanges on my DataSet's. You
apparently are doing something wrong. And since none of us a psychic we
can't tell you what you are doing wrong. Anyone who is going to help is
going to have to know all the relevant facts.

4 weeks! Maybe it's time to hire a consultant that knows what they are
doing?
 
If we ask questions in this forums is because WE ARE NOT PROGRAMMING
GURUS.....

And we don't hire consultants because we cannot afford it.

Were you born with the knowledge perhaps?...

The only way of knowing something you ignore is asking someone who knows
it.

It is not a secret that microsoft's software is always full of bugs and
inconsistancy (and lack of documentation)... I have 6 years of
experience programming on Windows based systems, and I still struggle
with microsoft's new versions of their products....

Why do you think Microsoft creates this forums?...

You know how much it would cost them to answer all of us frustrated
programmer's questions?

If you don't like the questions we ask here, then keep your comments to
yourself, and do not answer them.
 
Back
Top