I have some problems for updating a datasource from a datagrid.
My form has a dataset with 2 tables (tblCD_Detail and tblCD) which have a master detail relationship. There is also a datagrid (datagrid1) which displays the tblCD_detail fields corresponding with the selected tblCD.
The user can make changes in the datagrid, but the problem is how to update the corresponding datasource when the form is closed. Herefore I wrote the following code:
Private Sub test_Closing(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If dataset.HasChanges(DataRowState.Modified) Then
Dim commandbuilder As OleDbCommandBuilder
commandbuilder = New OleDbCommandBuilder(DACD_detail)
DACD_detail.Update(dataset, "tblCD_detail")
End If
end sub
I use the commandbuilder because I wrote the dataadapter myself (I didn't use the wizard), I also used the same dataadapter as the one I used to create the datatable tblCD_detail.
When I run the form, I don't get an error but my database isn't updated. Does anybody know what I'm doing wrong???
Has it something to do with the relationship between the tables?
I checked your code and I understand it, I used the same to code my dataset and datarelation. So, I think the problem has to be in the update of the datasource from the datagrid.
I simplified the application to get to the essence of the problem; now I have:
- a dataset
- a dataadapter to fill the dataset
- a datagrid with the dataset as datasource
- an update button to write the changes in the datagrid to the datasource.
When the users adds a row in the datagrid, then these changes are not send back to the database. I don't understand this because I don't get error messages.
The code is added inthe attachment, so you can take a look if you want.