473,387 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

parent column in child row

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
Nov 20 '05 #1
4 2866
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.com> 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

Nov 20 '05 #2
Hi Frank,

I have no direct answer, however when it was my problem I would add an extra
column to the childtable.

You can make a column like this
dim datatable.column.add(NameString,Type, expression)

http://msdn.microsoft.com/library/de...odatatable.asp

This is how to use an expression, what I did never do was with a parent
table, however it is described I saw.

http://msdn.microsoft.com/library/de...ssiontopic.asp

I never tried it.

However I hope it helps?

Cor
Nov 20 '05 #3
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(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

' Open a database connection.

Dim strConnection As String = _

"Data Source=localhost;Initial Catalog=Northwind;" _

& "Integrated Security=True"

Dim cn As SqlConnection = New SqlConnection(strConnection)

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.CustomerID = Orders.CustomerID)" _

& " AND (Customers.City = 'Buenos Aires')" _

& " AND (Customers.Country = '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.Add("CustomerOrders", _

ds.Tables("Customers").Columns("CustomerID"), _

ds.Tables("Orders").Columns("CustomerID"))

' Create a child row calculated column that shows

' a datacolumn from the child row's parent.

Dim companyNameColumn As New DataColumn("CompanyName",
System.Type.GetType("System.String"))

companyNameColumn.Expression = "Parent.CompanyName"

ds.Tables("Orders").Columns.Add(companyNameColumn)

Me.DataGrid1.DataSource = ds

End Sub

"Frank" <fr***@frank.com> 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.com> 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


Nov 20 '05 #4
Mike and Cor,
thanks!!!, especially the last lines of the detailed code from Mike helped.
I looked into the added datacolumn myself but I could not get the expression
do what I wanted. But it turns out to be more simple than I thought. Strange
that I didn't find an example like Mikes, maybe I used the wrong search
keywords.
Frank

"Mike McIntyre [MVP]" <mi****@dotnetshowandtell.com> wrote in message
news:e$**************@TK2MSFTNGP10.phx.gbl...
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...us/cpref/html/
frlrfsystemdatadatacolumnclassexpressiontopic.asp
http://msdn.microsoft.com/library/de...us/cpguide/htm
l/cpconaddingdatacolumnstodatatable.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(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

' Open a database connection.

Dim strConnection As String = _

"Data Source=localhost;Initial Catalog=Northwind;" _

& "Integrated Security=True"

Dim cn As SqlConnection = New SqlConnection(strConnection)

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.CustomerID = Orders.CustomerID)" _

& " AND (Customers.City = 'Buenos Aires')" _

& " AND (Customers.Country = '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.Add("CustomerOrders", _

ds.Tables("Customers").Columns("CustomerID"), _

ds.Tables("Orders").Columns("CustomerID"))

' Create a child row calculated column that shows

' a datacolumn from the child row's parent.

Dim companyNameColumn As New DataColumn("CompanyName",
System.Type.GetType("System.String"))

companyNameColumn.Expression = "Parent.CompanyName"

ds.Tables("Orders").Columns.Add(companyNameColumn)

Me.DataGrid1.DataSource = ds

End Sub

"Frank" <fr***@frank.com> 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.com> 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



Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: ahaideb | last post by:
I have a table (relation) in my database: --------------- | parent | child | --------------- | 1 | 2 | | 1 | 3 | | 2 | 4 | | 2 | 5 ...
4
by: news.online.no | last post by:
In a query, I need too be able to show if a parent record has a child record. Using the query in a combo box too select record in a form. Thanks :)
13
by: Stuart McGraw | last post by:
I haven't been able to figure this out and would appreciate some help... I have two tables, both with autonumber primary keys, and linked in a conventional master-child relationship. I've...
0
by: DraguVaso | last post by:
Hi, I have in my VB.NET-application a DataGrid with two DataTables in with a Parent-Child-relationship defined. When the users clicks on a call in the DataGrid, i want to know the MappingName...
8
by: Richard L Rosenheim | last post by:
I have a dataset containing a parent table related to a child table. The child table contains an ID field (which is configured as autonumber in the datatable), the ID of the parent, plus some...
1
by: Aaron Smith | last post by:
I have a parent table that has one child table. The parent has a single field (ID, AutoIncrement, Seed 0, Step -1 in the DataSet, Seed 1, step 1, in DataSource). The child is linked to this ID...
0
by: Ambica Jain | last post by:
I have a data grid called Files, which has some columns like FileName, Col1, Col2, ... , Col8. Then i have a combobox which allows user to select from Col1 to Col8 and based on this selection, i...
2
by: Catch_22 | last post by:
Hi, I have a stored procedure that has to extract the child records for particular parent records. The issue is that in some cases I do not want to extract all the child records only a...
4
by: mikemiller.innova | last post by:
In Visual Studio 2005 SP1, I added a DataSet item into my project. I added 3 tables from SQL that have data and relationships. I added 2 lookup columns (lkp) to the DllVersions table in the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.