very slow when updating dataset using AcceptChanges

  • Thread starter Thread starter jaYPee
  • Start date Start date
J

jaYPee

does anyone experienced slowness when updating a dataset using
AcceptChanges?

when calling this code it takes many seconds to update the database

SqlDataAdapter1.Update(DsStudentCourse1)
DsStudentCourse1.AcceptChanges()

i'm also wondering because w/ out AcceptChanges the data is still save
into the database and it is now faster.

thanks in advance for any info.
 
From MSDN:

When using Update, the order of execution is as follows:
1.The values in the DataRow are moved to the parameter values.
2.The OnRowUpdating event is raised.
3.The command executes.
4.If the command is set to FirstReturnedRecord, then the first returned
result is placed in the DataRow.
6.If there are output parameters, they are placed in the DataRow.
7.The OnRowUpdated event is raised.
8.AcceptChanges is called.

So don't need to call explicitly AcceptChanges because the Update method
already does this.


Ernest
 
Thank you very much for the reply. however i have this scenario that
if i don't use AcceptChanges the record in the datagrid (which
contains related table) is not showing

this is the scenario:

i have a parent/child form that after clicking a checkbox in the
parent form the program will execute the stored procedure from sql
server 2000 then save the data in the related table that is based on
the criteria from the primary table and filling the datagrid (which
contains related table)

but i can't see the changes after clicking the checkbox if i don't use
AcceptChanges after an update.

thanks again for any info.
 
Hi jaYPee,

I have seen this as well, it is a weird scenario. Confirming to the
documentation this should not be necessary, however it is, it seems in my
eyes something with the datasource and not with the datagrid.

There was a kind of the same message from Herfried yesterday about an
arraylist.

Cor
 
jayYPee,
Do you have a sample app that identifies this problem.

Are you updating both the Parent & the Child? Are you updating the tables in
the correct order? Are you updating rows in the correct order? (for possible
issues on updating in the correct order see Sceppa's book below).

As Ernest & Cor have stated, calling AcceptChanges after Update should not
be needed, as Update does call AcceptChanges!

You may have stumbled on a bug in the framework (either the dataset or the
datagrid), hence my asking if you have a sample that identifies the problem.
Especially if you can consistently recreate it.

For a good tutorial on ADO.NET as well as a good desk reference once you
know ADO.NET see David Sceppa's book "Microsoft ADO.NET - Core Reference"
from MS press.

Hope this helps
Jay
 
Hi Jay,

I have already made an very simple sample not this problem however it looks
as this and sended it to the ADONET group in a discussion, however the
thread stopped after I had send it.

Are you interested?

Cor
 
Hi Jay,

I have already made an very simple sample not this problem however it looks
as this and sended it to the ADONET group in a discussion, however the
thread stopped after I had send it.

Are you interested?

Cor

yes i'm interested
 
Hi jaYpee,

Whith that sample I show the behaviour that you tell.

(It has to do with the position of a row in a datagrid)

With acceptchanges it is after an insert on the right place, while it is
whithout that at the end.

However for me a kind of same behaviour, as you tell.

(Adding rows in a datagrid and doing an acceptchanges after that is useless
of course, this for the ones who maybe will google this thread onces)

However the sample gives no solution.

Sorry

Cor
 
Cor,
Can you either post the code or email me it (a linke would work as well). I
don't really have time right now to search the ado group for it.

Thanks
Jay
 
Jay,

This is one from the test I did, I also did it with SetDatabinding (when you
want that, it was even smaller, reply than) the result was almost the same
however more difficult to explain.

You see in this sample not the acceptchanges however when that is done with
everything enabled the rows are as well presented in the way as what it in
my opinion should be.

Maybe you find why this behaviour is, I could not find one "logical" clue.

Cor


It needs only a form with a datagrid and this in the loadform event. After
that you have to delete the two ' , to show what I mean.

\\\
Dim ds As New DataSet
Dim dt As New DataTable("Bill")
ds.Tables.Add(dt)
dt.Columns.Add("Ryan")
For i As Integer = i To 3
dt.Rows.Add(dt.NewRow)
dt.Rows.Item(i)(0) = i.ToString
Next
'DataGrid1.DataSource = dt
'with above endabled the datagrid shows 0 1 2 3 4
'DataGrid1.DataSource = Nothing
'now with these two rows disabled it displays 0 1 4 2 3
Dim dr As DataRow = dt.NewRow
dr(0) = "4"
dt.Rows.InsertAt(dr, 2)
DataGrid1.DataSource = dt
///
 
Back
Top