Parent/Child relationship

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

i have two table

ParentID and I can't seem to figure out how to get the ParentID from the Parent table so I can save it in the child table

Any suggestions

regards
MeKim
 
Hi Mekim,

Sorry, however I do not understand your question.
ParentID and I can't seem to figure out how to get the ParentID from the
Parent table so I can save it in the child table.

Use as select string for your dataadatatper fill, Select ParentId from
Parent

That seems all for me, however I do not believe you are asking something
simple like that.

Cor
 
Hi Mekim,

For that you do as far as I know not need a relation. The relation you can
use to show the table in a relational order in by instance a datagrid, what
you are doing, the Id is enough, that is the relation.

When I translate your program than it says. Make a dataset dbSet with two
empty tables from the database tableparent and tablechild. Fill in both a
row one with the systemdate and one with ticks.

Update both the tables from the dataset. For this it is very complete, I
delete what for this I think is not really needed now.
Public Sub AddingParentChildRecords()
Dim dbConn As New OleDbConnection(constConnectionString)
dbConn.Open()

Dim dbSet As New DataSet
Dim dbParentAdapt As OleDbDataAdapter
dbParentAdapt = New OleDbDataAdapter("SELECT * FROM TableParent", dbConn)

Dim dbParentCB As New OleDbCommandBuilder(dbParentAdapt)
dbParentAdapt.FillSchema(dbSet, SchemaType.Source)
Dim dbChildAdapt As New OleDbDataAdapter("SELECT * FROM TableChild", dbConn)
Dim dbChildCB As New OleDbCommandBuilder(dbChildAdapt)
dbChildAdapt.FillSchema(dbSet, SchemaType.Source)
Dim oParentRow As DataRow = dbSet.Tables("TableParent").NewRow()
oParentRow("ParentText") = Now().ToString
dbSet.Tables("TableParent").Rows.Add(oParentRow)

Dim oChildRow As DataRow = dbSet.Tables("TableChild").NewRow()
oChildRow("ChildText") = Now().Ticks.ToString
dbParentAdapt.Update(dbSet, "TableParent")
dbChildAdapt.Update(dbSet, "TableChild")

dbConn.Close()
End Sub

When there is a relation in your database Parent -> Child than the Parent
first.

And because that everything in .Net is an object I would not use that o.

Cor
 
Back
Top