Frank,
You can do what you want by adding a calculated column to the child
DataTable that contains and expression that references a parent row column.
Learn more at the links below:
http://msdn.microsoft.com/library/de...ssiontopic.asp http://msdn.microsoft.com/library/de...odatatable.asp
Below is some code for a button click handler that demonstrates how to
accomplish your goal. If you create a Windows Forms project, add a Button1
and a DataGrid1, add this code below to the form code, and make sure the
SqlConnection is valid for your Sql server you can see this code in action.
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
' Open a database connection.
Dim strConnection As String = _
"Data Source=localhos t;Initial Catalog=Northwi nd;" _
& "Integrated Security=True"
Dim cn As SqlConnection = New SqlConnection(s trConnection)
cn.Open()
' Set up a data adapter object.
Dim strSql As String = "SELECT * FROM Customers" _
& " WHERE City = 'Buenos Aires' AND Country = 'Argentina'"
Dim da As SqlDataAdapter = New SqlDataAdapter( strSql, cn)
' Load a data set.
Dim ds As DataSet = New DataSet()
da.Fill(ds, "Customers" )
' Set up a new data adapter object.
strSql = "SELECT Orders.*" _
& " FROM Customers, Orders" _
& " WHERE (Customers.Cust omerID = Orders.Customer ID)" _
& " AND (Customers.City = 'Buenos Aires')" _
& " AND (Customers.Coun try = 'Argentina')"
da = New SqlDataAdapter( strSql, cn)
' Load the data set.
da.Fill(ds, "Orders")
' Close the database connection.
cn.Close()
' Create a relation.
ds.Relations.Ad d("CustomerOrde rs", _
ds.Tables("Cust omers").Columns ("CustomerID "), _
ds.Tables("Orde rs").Columns("C ustomerID"))
' Create a child row calculated column that shows
' a datacolumn from the child row's parent.
Dim companyNameColu mn As New DataColumn("Com panyName",
System.Type.Get Type("System.St ring"))
companyNameColu mn.Expression = "Parent.Company Name"
ds.Tables("Orde rs").Columns.Ad d(companyNameCo lumn)
Me.DataGrid1.Da taSource = ds
End Sub
"Frank" <fr***@frank.co m> wrote in message
news:c9******** **@news3.tilbu1 .nb.home.nl...
Is this question so difficult or is it impossible what I want? I can't be
the first one to bump into this problem. Plse tell me if it is not
possible then I can look into another direction.
Frank
"Frank" <fr***@frank.co m> wrote in message
news:c9******** **@news3.tilbu1 .nb.home.nl... Hello,
I have a dataset with 2 tables and a relation (parent - child). I linked
that ds to a datagrid. Shows everything fine (very little coding for
such functionality!) .
But.. in the child row I want to show a column of the parent. Example:
orderColumn shows customerId and I want the customerName which is
located in the parent.
How do I do that?
Thanks in advance
Frank