Database update question (reworded)

F

FST

Hello all,

After I've used the OleDbDataAdapter to fill a datagrid from the Form1_Load
event then I run the following code:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

OleDbDataAdapter1.Update(DataSet11)
MessageBox.Show("Database updated")

End Sub

The database gets updated as it should, but if I run the
OleDbDataAdapter1.Update(DataSet11) from inside the
DataGrid1_CurrentCellChanged event the database doesn't update:

Private Sub DataGrid1_CurrentCellChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DataGrid1.CurrentCellChanged

OleDbDataAdapter1.Update(DataSet11)
MessageBox.Show("DataGrid1_CurrentCellChanged")

End Sub

Does anyone know, why the database updates from inside the Button1_Click
event, but won't
update from inside the DataGrid1_CurrentCellChanged event?

Thanks,

Fred
 
C

CJ Taylor

I would assume that the changes have been made to the column, but not
necessarily on the row itself within the datagrid.

Unfortunatly, there is no event data on when the dataset has been modified
(.NET 1.2?) but it would be nice if a rowevent existed.

You could, take your inherited dataset, and create your own event handler
for RowUpdated and fire when the property is set. AND THEN do your event
handling.

Hope it helps.

-CJ
 
F

FST

Thanks CJ. For now just changing rows also fires the
DataGrid1_CurrentCellChanged event then the record gets saved.

F
 
C

CJ Taylor

I just realized and don't know how I missed it, but if you create a dataset
within VS.NET with the code behind, it creates event handlers and the
associated delegates for a RowChangedEvent...

Check it ou

-CJ
 
D

Don B

FST said:
Thanks CJ. For now just changing rows also fires the
I would assume that the changes have been made to the column, but not
necessarily on the row itself within the datagrid.

Unfortunatly, there is no event data on when the dataset has been modified
(.NET 1.2?) but it would be nice if a rowevent existed.


Private Sub DataGrid1_CurrentCellChanged(ByVal sender As Object, ByVal
e As System.EventArgs) Handles DataGrid1.CurrentCellChanged

If DataSet11.HasChanges Then
DataSet11.AcceptChanges()
OleDbDataAdapter1.Update(DataSet11)
MessageBox.Show("DataGrid1_CurrentCellChanged")
End If


Give that a try and see if it works.
 
C

CJ Taylor

Don B said:
"FST" <[email protected]> wrote in message
I would assume that the changes have been made to the column, but not


Private Sub DataGrid1_CurrentCellChanged(ByVal sender As Object, ByVal
e As System.EventArgs) Handles DataGrid1.CurrentCellChanged

If DataSet11.HasChanges Then
DataSet11.AcceptChanges()
OleDbDataAdapter1.Update(DataSet11)
MessageBox.Show("DataGrid1_CurrentCellChanged")
End If

Don,

This will not do anything... Because you call DataSet11.Acceptchanges
BEFORE you call the update, it will set each RowState to Unmodified
(thinking its already been updated).

Therefore, the DataAdapter will not update because it thinks nothing has
changed.
 
D

Don B

CJ Taylor said:
Don,

This will not do anything... Because you call DataSet11.Acceptchanges
BEFORE you call the update, it will set each RowState to Unmodified
(thinking its already been updated).

Therefore, the DataAdapter will not update because it thinks nothing has
changed.
Doh. What i meant was:

If DataSet11.HasChanges Then
OleDbDataAdapter1.Update(DataSet11)
DataSet11.AcceptChanges()
MessageBox.Show("DataGrid1_CurrentCellChanged")
End If

i blame this horrid web interface. Cant use a newsreader here at work
because the facist admins wont allow them ;)


ps Love that email :)
 
C

CJ Taylor

Don B said:
"CJ Taylor" <[email protected]> wrote in message
Doh. What i meant was:

If DataSet11.HasChanges Then
OleDbDataAdapter1.Update(DataSet11)
DataSet11.AcceptChanges()
MessageBox.Show("DataGrid1_CurrentCellChanged")
End If

i blame this horrid web interface. Cant use a newsreader here at work
because the facist admins wont allow them ;)

I can understnad that... And google groups are slow.
ps Love that email :)


Subtle, but effective. ;)
 

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