Updating one table in a two-table relationship
Posted on 2006-11-09
I have two related tables.
The first table holds member information, the second group information.
The member is part of a group (duh)
On startup, all my controls (unbound) are filled with correct data, and also my datagrid
When I add a new member, the data for the member table is saved, along with the key relating it to the second table.(groupID)
The actual updating is working OK, but immediately after the update, the line in the datagrid holding the info for the new member (row) is all screwed up.
It only shows nulls and second table data.
The datagrid is supposed to show only 1 column of the second table.
memberID | Name | Surname | Date | Group (2nd table)
When I close the app, and restart, the latest added record is displayed OK.
The datagrid is the only bound control. The members table has an autonumber for memberID.
This is my code :
strSQL = "Select * from tblleden"
Dim AddLid_DA As New OleDb.OleDbDataAdapter(strSQL, conn)
Dim AddLid_DS As New DataSet
Dim AddLid_DT As DataTable
Dim AddLid_DR As DataRow
Dim custCB As OleDb.OleDbCommandBuilder = New OleDb.OleDbCommandBuilder(AddLid_DA)
AddLid_DT = AddLid_DS.Tables("Lid")
AddLid_DR = AddLid_DT.NewRow
AddLid_DR("date") = TextBox13.Text
AddLid_DR("groupid") = groupID
AddLid_DR("Name") = TextBox13.Text
AddLid_DR("SurName") = TextBox14.Text
Dim modified As DataRow() = AddLid_DS.Tables("Lid").Select(Nothing, Nothing, DataViewRowState.Added)
da.Fill(ds, "Leden") --->ds = the original two-table dataset