Datagrids

M

mfleet1973

Hello. I'm fairly new to VB.Net (2003). I'm using a datagrid to
display data (access db) and when user double clicks on a record,
another form shows up which allows modification/addition of data. The
problem is when user accepts the changes made and gets back to
datagrid. The information displayed is still the old info. How do I
get the new information to display? Here is an example of the code
used to update the data:

objDataSet.Tables("Table").Rows(objCurrencyManager.Position).BeginEdit()
objDataRow =
objDataSet.Tables("Table").Rows(objCurrencyManager.Position)

With objDataRow
.Item("Field1") = Text1.Text
End With
objDataRow.AcceptChanges()
objDataSet.Tables("Table").Rows(objCurrencyManager.Position).AcceptChanges()

Shouldn't the data in the datagrid diplay the information that was
entered in Text1.Text? Or is it that I'm doing something wrong?

Many thanks for any replies!!
 
B

bob

Cor, I am not clear on what you mean by saying "If means something as
Accept changes as done." Does this mean you should AcceptChanges
(update the database on disk) only when you are done and exit the
DataGrid/program, and not during the editing process? Or, is it
recommended to confirm/write/update a small portion of the data (ie,
the row you just changed) right away? If the latter, how to you do
that?

Thanks.
(e-mail address removed)
 
C

Cor Ligthert [MVP]

Bob,

I cannot answer yes or no on your question, because when you do the database
updates while editing it can be that you use it. But it has forever to do
with update from a database as long as you don't do that, you normally
should not use the acceptchanges.

The acceptchanges can be used by instance in this sentence.

myDataAdapter.Update(myDataTable.getchanges)
Not that this gives any advantage but let assume.

The dataadapter marks the rowstate of rows which are done as not changed.

But the myDataTable.getchanges is a copy of the datatable, so it has to be
done in the origanal as well.

Therefore than the myDataTable.acceptchanges which means that those rows
will not be updated again.

I hope that this makes it a little bit clear because there are not much
samples to give where it has to be used. It is not rare to use it, but there
are very few places (a cascade update by instance can need it as well).

Cor
 
B

bob

Hey, now I think I see what you mean. I saw this mentioned in the book
"Programming Visual Basic.net" by Francesco Balena (first edition). He
warned not to ever use the AcceptChanges command, becuase of what you
are saying -- the "dataset" gets updated, but not the disk file. Thanks
for your message.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top