473,770 Members | 1,629 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2893
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

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.colum n.add(NameStrin g,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(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


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****@dotnets howandtell.com> wrote in message
news:e$******** ******@TK2MSFTN GP10.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/
frlrfsystemdata datacolumnclass expressiontopic .asp
http://msdn.microsoft.com/library/de...us/cpguide/htm
l/cpconaddingdata columnstodatata ble.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



Nov 20 '05 #5

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

Similar topics

1
9122
by: ahaideb | last post by:
I have a table (relation) in my database: --------------- | parent | child | --------------- | 1 | 2 | | 1 | 3 | | 2 | 4 | | 2 | 5 | | 3 | 6 |
4
2640
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
7409
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 created forms for both those tables, and inserted the child table form into the master table form as a subform. It works just as it is supposed to, in that I can create a new master record, and then add detail records.
0
1165
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 of the Column. This is easy with only one table, but with 2 tables defined I'm not able to know on which Table the User is currently looking (the parent of the child), so I don't know if I should look at the Parent-tablestyle or the...
8
3927
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 addition fields. I'm able to get the datagrid to be properly populate with only the child records relating to the specified parent by setting the ..DefaultView.RowFilter property. Currently, to properly add a new child record, I need to manually...
1
2217
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 column in the parent. I have the parent fields in textboxes and the child is a DataGrid. When I add a new parent record, then go to add child records, I am getting an exception that says, "ForeignKeyConstraint requires the child key values (0) to...
0
2912
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 generate a report from data in grid Files. It displays like (e.g. is Col1 is selected): Col1 Count ---------------------- Val1 x Val2 y .....
2
3335
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 certain number of them. Firstly I identify all the parent records that have the requird number of child records and insert them into the result table.
4
1889
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 dataset ProjectID
0
9595
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10232
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10059
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10008
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9873
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7420
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5313
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5454
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3974
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.