Hi Experts,
I have a windows form linked to a back-end MS Access database. This database is replicated and the primary key for the table in question is a randomized autoincrement long integer.
On my front-end windows form I have a bindingnavigator that allows me to move through the tables data.
When I create a new record on the windows form (using the bindingnavigatoradd button) it adds a new record for me to update - but just autoincrements the primary key field by 1. Then when I save back to the MS database this figure (previous + 1) is replaced by a randomized number.
The problem I have is that there is a second 'sub' table that I store additional information in, using the primary key from the main table as the link. Therefore it's storing the wrong primary key as it stores the one shown on the windows form - which is updated by MS Access when the datasets are saved.
My questions are:
1) Am I attempting to do this the correct way (i.e. MS Access is controlling the random primary keys)? I think it has to be this was to allow Access to handle any duplicates?
2) Assuming this is the way to do it - how can I update MS Access on adding a new record and then obtain the new randomized number. I've tried saving the record (using the code below) on the BindingNavigatorAddNewItem
_Click event, but this doesn't work. This seems to fire before the item is added not after.
Me.BindingSource1.EndEdit(
)
Me.TableAdapter1.Update(Me
.MasterDat
aSet1.Tabl
e1)
Me.TableAdapter1.Fill(Me.M
asterDataS
et1.Table1
)
Help as usual much appreciated,
Many Thanks,
Sam
Start Free Trial