Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DATASET and CHildrecords

Status
Not open for further replies.

Vandy02

Programmer
Jan 7, 2003
151
US
I have a dataset with two tables..."DEPT", "EMP"
They have column "DEPTNO" in common...
I have made a relation and tied the dataset to a datagrid "dgDEPT" and the relationship works.

What I want to do is have a grid as the DEPT table and when I select on a record...I want a separate grid to show the child records...any idea?

At present dgDEPT shows the DEPT records and has "+" so I can look at the child records
=====================================================
Dim strEMP, strDEPT As String
strEMP = "Select * from EMP"
strDEPT = "Select * from DEPT"

Dim dsEMP = New DataSet


Dim daEMP = New OleDb.OleDbDataAdapter(strEMP, conn)
Dim daDEPT = New OleDb.OleDbDataAdapter(strDEPT, conn)

daEMP.Fill(dsEMP, "EMP")
daDEPT.Fill(dsEMP, "DEPT")
conn.Close()

'EXAMPLE OF MANUAL BINDING

dsEMP.Relations.Add("MINE", dsEMP.Tables("DEPT").Columns("DEPTNO"), dsEMP.Tables("EMP").Columns("DEPTNO"))

dgDEPT.SetDataBinding(dsEMP, "DEPT")

==============================================

thanks
 
Vandy02,

In order to get the second datagrid to show the child records for the main grid selection you may want to try this. Instead of getting 2 tables, make 1 table as a join of the two. The set each datagrids table style and column style to show only the information that you want. Then set each grids datasource to that table. This should allow a selection in 1 to bring up the corresponding row in the other.

Hope this helps,

Brian
 
This is what I obtained from the link..
However, when I use mine I get an error...

"Overload resolution failed because no accessible 'NEW'
can be called without narrowing conversion"

Can someone try this...

' Visual Basic
Dim myDataRelation As DataRelation
myDataRelation = New DataRelation _
("CustOrd", ds.Tables("Customers").Columns("CustomerID"), _
ds.Tables("Orders").Columns("CustomerID"))
' Add the relation to the DataSet.
ds.Relations.Add(myDataRelation)
GridOrders.SetDataBinding(ds, "Customers")
GridDetails.SetDataBinding(ds, "Customers.CustOrd")


=====MINE
Dim strEMP, strDEPT As String
strEMP = "Select * from EMP"
strDEPT = "Select * from DEPT"

Dim daEMP = New OleDb.OleDbDataAdapter(strEMP, oOleDbConnection)
Dim daDEPT = New OleDb.OleDbDataAdapter(strDEPT, oOleDbConnection)
daEMP.Fill(ds, "EMP")
daDEPT.Fill(ds, "DEPT")
oOleDbConnection.Close()
dgDEPT.SetDataBinding(ds, "DEPT") 'to make sure table is obtained --good
dgEMP.SetDataBinding(ds, "EMP") 'to make sure table is obtained -good

'EXAMPLE OF MANUAL BINDING

Dim myDataRelation As DataRelation

myDataRelation = New DataRelation("DEPTLIST", ds.Tables("DEPT").Columns("DEPTNO"), _
ds.Tables("EMP").Columns("DEPTNO"))
 
I'm not sure about that one. You might try referencing the Tables and Columns by index rather than string name.
 
well, i tried this and at least i get to the form this time...but i get another error...i changed the format so I could get to the form...any idea with the error?


myDataRelation = New DataRelation("DEPTLIST", ds.Tables(0), ds.Tables(0).Columns("DEPTNO"), ds.Tables(1), ds.Tables(1).Columns("DEPTNO"), True)

An unhandled exception of type 'System.InvalidCastException' occurred in microsoft.visualbasic.dll

Additional information: Cast from type 'DataTable' to type 'String' is not valid.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top