Click here to Skip to main content
Licence 
First Posted 6 Apr 2004
Views 21,870
Bookmarked 11 times

ADO Relate 2 tables by more then one field

By | 6 Apr 2004 | Article
Relate 2 tables by more then one field

Introduction

The way to stablish a System.Data.DataRelation betwin 2 System.Data.DataTable's by 2 or more System.Data.datacolumn's.

In this example u must asume the existence of 2 DataTables in the DS_Geral DataSet with the acording fields ...

Sub Ex()
Dim DR_Afectacao_Producao as System.Data.DataRelation

Dim Parent (1) as System.Data.datacolumn
Dim Child (1) as System.Data.datacolumn
'This arrays of datacolumns must be delimited by the number of fields <BR>'conected in the relation, 
'thei are <FONT color=#008000>0-based</FONT>

       Parent (0) = DT_Afectacao.Columns("id_prod") 'The parent Table 
       Parent (1) = DT_Afectacao.Columns("id_xnuc") 'The parent Table
       Child (0) = DT_Producao.Columns("id_prod") 'The child Table
       Child (1) = DT_Producao.Columns("id_xnuc") 'The child Table


DR_Afectacao_Producao =  new Datarelation ("Afect_Producao", Parent, Child, _<BR>                                             false )
DS_Geral.Relations.Add(DR_Afectacao_Producao)
End Sub

Example 1 Geting the Child Rows:
Dim ChildRows_1(), foundRow As DataRow

foundRow = DT_Afectacao.Rows.Find(Sender.Selecteditem.value)
ChildRows_1 = foundRow.GetChildRows("Afect_Producao")
Result:  ChildRows_1 is an Array of all of the child Rows ...

Example 2 Geting the Parent row:

Dim founded_ParentRow , foundRow As DataRow

foundRow = DT_Producao.Rows.Find(Sender.Selecteditem.value)
founded_ParentRow = foundRow.GetParentRow("Afect_Producao")
Result: foundParentRow is a DataRow in the parent DataTable of the relation ...

Summary:

The  "Rows.Find"  only finds key-values ... in the key-column of the DataTable

 

 

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Jose Xavier

Web Developer

Portugal Portugal

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 5 PinmemberHeaven20208:58 3 Nov '10  
General... Pinmembergrim4ik0:35 25 Sep '08  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120517.1 | Last Updated 7 Apr 2004
Article Copyright 2004 by Jose Xavier
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid