insert into two tables with one-to-one relationship troubles
- From: "Craig Buchanan" <someone@xxxxxxxxxxxxx>
- Date: Tue, 8 Nov 2005 20:36:29 -0600
i have two Access tables: Item and Contact. Id is the PrimaryKey for the
Item table. It is an autonumber field. It relates to the ItemId field in
the Contact table. This is a one-to-one relationship. Referential
integrity is enforced; Cascading Deletes and Updates are enabled. ItemId
has not been defined to be the PrimaryKey of the Contact table.
When i run code to insert a row into both tables, the ItemId field isn't
being updated. What am i missing? Does the ItemId field need to be marked
as the PrimaryKey? do i need to explicitly update the ItemId field, then
..Update again? I'm able to run an insert query in the query painter
successfully.
Thanks,
Craig
<code>
...
Dim commandText As String: commandText = "SELECT * FROM Item INNER JOIN
Person ON Item.Id=Person.ItemId WHERE Id=" & m_Id
Dim RS As New ADODB.Recordset
With RS
.ActiveConnection = MDB_DATA
.CursorLocation = adUseClient
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open commandText
If .BOF And .EOF Then
.AddNew
End If
'Item fields
.Fields("ParentId") = m_ParentId
'contact fields
.Fields("FirstName") = m_FirstName
.Fields("LastName") = m_LastName
.Update
'get the value of the autoincrement field
m_Id = .Fields("Id")
End With
...
</code>
.
- Prev by Date: Re: MDAC and win XP sp2
- Next by Date: Re: Custom marshalling of ADO.NET dataset to ADO Recordset
- Previous by thread: Re: MDAC and win XP sp2
- Next by thread: RE: Microsoft Access and Transaction Isolation Level
- Index(es):