473,779 Members | 2,001 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Binding a grid to master/detail related datatables

Picture the cut down scenario...

Say I have three datatables (Person, Address, Street) that are linked with
datarelation objects using the PK/FK associations...

Person
--------
PersonId {PK}
AddrId {FK}
Forename
....
Address
----------
AddrId {PK
StreetId {FK}
HouseName
....
Street
-------
StreetId {PK}
StreeName

How can I BIND a datagrid to the Person datatable to show all person rows
and include data from Parent table (HouseName from Address) and from the
parent table again (StreetName from Street) for each row.

Grid example
---------------

PersonId | Forename | HouseName | StreetName
_______________ _______________ ___________
1 Bill billshouse York Street
2 Stan stanshouse York Street
3 Tom tomshouse New Street
etc

I know you can do the reverse. So for this scenario you could have a
hierarchical grid binding to the master datatable Street and working down to
the detail person but I don't want that.

Any help appreciated!
Apr 18 '07 #1
4 2461
I would use Joins in your SQL Query that retrieves the data. Typically I
recommend Stored Procedures for accessing your database, but that usually
depends on your work environment. The SQL Query to pull the data you are
looking for goes like this:

SELECT Person.PersonID ,
Person.Forename ,
Address.HouseNa me,
Street.StreeNam e
FROM Person
JOIN Address ON Adress.AddrId = Person.AddrId
JOIN Street ON Sreet.StreetID = Address.StreetI d
The above SQL Query should give you the data you need. You can take that
data and bind it to your GridView. I have found the following website to be
very useful in answering any questions I may have about SQL. I would also
point out that performing an operation like this is usually most easily done
in a language like SQL, not an imperative language like C#, but that may
change in C# 3.0. http://www.w3schools.com/sql/default.asp
"J.Matthews " wrote:
Picture the cut down scenario...

Say I have three datatables (Person, Address, Street) that are linked with
datarelation objects using the PK/FK associations...

Person
--------
PersonId {PK}
AddrId {FK}
Forename
...
Address
----------
AddrId {PK
StreetId {FK}
HouseName
...
Street
-------
StreetId {PK}
StreeName

How can I BIND a datagrid to the Person datatable to show all person rows
and include data from Parent table (HouseName from Address) and from the
parent table again (StreetName from Street) for each row.

Grid example
---------------

PersonId | Forename | HouseName | StreetName
_______________ _______________ ___________
1 Bill billshouse York Street
2 Stan stanshouse York Street
3 Tom tomshouse New Street
etc

I know you can do the reverse. So for this scenario you could have a
hierarchical grid binding to the master datatable Street and working down to
the detail person but I don't want that.

Any help appreciated!

Apr 18 '07 #2
anonymous,

You know his next post is going to be, "I used the SqlCommandBuild er to
build my command objects, but it won't update the database." ;-)

J.Matthews -- I agree with anonymous that this is the way to go. But if you
want to do updates, you will need to program them manually.

Robin S.
----------------------------------
"anonymous" <an*******@disc ussions.microso ft.comwrote in message
news:42******** *************** ***********@mic rosoft.com...
>I would use Joins in your SQL Query that retrieves the data. Typically I
recommend Stored Procedures for accessing your database, but that usually
depends on your work environment. The SQL Query to pull the data you are
looking for goes like this:

SELECT Person.PersonID ,
Person.Forename ,
Address.HouseNa me,
Street.StreeNam e
FROM Person
JOIN Address ON Adress.AddrId = Person.AddrId
JOIN Street ON Sreet.StreetID = Address.StreetI d
The above SQL Query should give you the data you need. You can take that
data and bind it to your GridView. I have found the following website to
be
very useful in answering any questions I may have about SQL. I would
also
point out that performing an operation like this is usually most easily
done
in a language like SQL, not an imperative language like C#, but that may
change in C# 3.0. http://www.w3schools.com/sql/default.asp
"J.Matthews " wrote:
>Picture the cut down scenario...

Say I have three datatables (Person, Address, Street) that are linked
with
datarelation objects using the PK/FK associations...

Person
--------
PersonId {PK}
AddrId {FK}
Forename
...
Address
----------
AddrId {PK
StreetId {FK}
HouseName
...
Street
-------
StreetId {PK}
StreeName

How can I BIND a datagrid to the Person datatable to show all person
rows
and include data from Parent table (HouseName from Address) and from the
parent table again (StreetName from Street) for each row.

Grid example
---------------

PersonId | Forename | HouseName | StreetName
______________ _______________ ____________
1 Bill billshouse York Street
2 Stan stanshouse York Street
3 Tom tomshouse New Street
etc

I know you can do the reverse. So for this scenario you could have a
hierarchical grid binding to the master datatable Street and working
down to
the detail person but I don't want that.

Any help appreciated!


Apr 18 '07 #3
Thanks for the replies. Yes that would have been my reply comment (regarding
updating). Ok, then I will have to program the updating manually

Thanks

"RobinS" wrote:
anonymous,

You know his next post is going to be, "I used the SqlCommandBuild er to
build my command objects, but it won't update the database." ;-)

J.Matthews -- I agree with anonymous that this is the way to go. But if you
want to do updates, you will need to program them manually.

Robin S.
----------------------------------
"anonymous" <an*******@disc ussions.microso ft.comwrote in message
news:42******** *************** ***********@mic rosoft.com...
I would use Joins in your SQL Query that retrieves the data. Typically I
recommend Stored Procedures for accessing your database, but that usually
depends on your work environment. The SQL Query to pull the data you are
looking for goes like this:

SELECT Person.PersonID ,
Person.Forename ,
Address.HouseNa me,
Street.StreeNam e
FROM Person
JOIN Address ON Adress.AddrId = Person.AddrId
JOIN Street ON Sreet.StreetID = Address.StreetI d
The above SQL Query should give you the data you need. You can take that
data and bind it to your GridView. I have found the following website to
be
very useful in answering any questions I may have about SQL. I would
also
point out that performing an operation like this is usually most easily
done
in a language like SQL, not an imperative language like C#, but that may
change in C# 3.0. http://www.w3schools.com/sql/default.asp
"J.Matthews " wrote:
Picture the cut down scenario...

Say I have three datatables (Person, Address, Street) that are linked
with
datarelation objects using the PK/FK associations...

Person
--------
PersonId {PK}
AddrId {FK}
Forename
...
Address
----------
AddrId {PK
StreetId {FK}
HouseName
...
Street
-------
StreetId {PK}
StreeName

How can I BIND a datagrid to the Person datatable to show all person
rows
and include data from Parent table (HouseName from Address) and from the
parent table again (StreetName from Street) for each row.

Grid example
---------------

PersonId | Forename | HouseName | StreetName
_______________ _______________ ___________
1 Bill billshouse York Street
2 Stan stanshouse York Street
3 Tom tomshouse New Street
etc

I know you can do the reverse. So for this scenario you could have a
hierarchical grid binding to the master datatable Street and working
down to
the detail person but I don't want that.

Any help appreciated!



Apr 19 '07 #4
That's pretty much the level of progression. I just thought I'd answer it
before you asked.

Good luck!
Robin S.
-----------------
"J.Matthews " <JM*******@disc ussions.microso ft.comwrote in message
news:3C******** *************** ***********@mic rosoft.com...
Thanks for the replies. Yes that would have been my reply comment
(regarding
updating). Ok, then I will have to program the updating manually

Thanks

"RobinS" wrote:
>anonymous,

You know his next post is going to be, "I used the SqlCommandBuild er to
build my command objects, but it won't update the database." ;-)

J.Matthews -- I agree with anonymous that this is the way to go. But if
you
want to do updates, you will need to program them manually.

Robin S.
----------------------------------
"anonymous" <an*******@disc ussions.microso ft.comwrote in message
news:42******* *************** ************@mi crosoft.com...
>I would use Joins in your SQL Query that retrieves the data. Typically
I
recommend Stored Procedures for accessing your database, but that
usually
depends on your work environment. The SQL Query to pull the data you
are
looking for goes like this:

SELECT Person.PersonID ,
Person.Forename ,
Address.HouseNa me,
Street.StreeNam e
FROM Person
JOIN Address ON Adress.AddrId = Person.AddrId
JOIN Street ON Sreet.StreetID = Address.StreetI d
The above SQL Query should give you the data you need. You can take
that
data and bind it to your GridView. I have found the following website
to
be
very useful in answering any questions I may have about SQL. I would
also
point out that performing an operation like this is usually most
easily
done
in a language like SQL, not an imperative language like C#, but that
may
change in C# 3.0. http://www.w3schools.com/sql/default.asp
"J.Matthews " wrote:

Picture the cut down scenario...

Say I have three datatables (Person, Address, Street) that are linked
with
datarelation objects using the PK/FK associations...

Person
--------
PersonId {PK}
AddrId {FK}
Forename
...
Address
----------
AddrId {PK
StreetId {FK}
HouseName
...
Street
-------
StreetId {PK}
StreeName

How can I BIND a datagrid to the Person datatable to show all person
rows
and include data from Parent table (HouseName from Address) and from
the
parent table again (StreetName from Street) for each row.

Grid example
---------------

PersonId | Forename | HouseName | StreetName
______________ _______________ ____________
1 Bill billshouse York Street
2 Stan stanshouse York Street
3 Tom tomshouse New Street
etc

I know you can do the reverse. So for this scenario you could have a
hierarchical grid binding to the master datatable Street and working
down to
the detail person but I don't want that.

Any help appreciated!




Apr 20 '07 #5

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

Similar topics

0
1105
by: Carlos | last post by:
I’m constructing a Windows Forms application that accesses SQLServer data via a dataset. The dataset contains 2 tables “tblMaster” and “tblDetail” which are related in a one-to-many relationship on the field “MasterID” (the primary key in “tblMaster” and the foreign key in “tblDetail”). Each table is bound to a datagrid at design time using the property window. The binding is as follows: masterDatagrid.datasource = dataset1...
8
2054
by: Christopher Weaver | last post by:
I'm having the hardest time doing the simplest thing. I have a DataGrid bound to a table in a master detail DataRelation within a DataSet relTaskActivities = new DataRelation("TaskActivities", parentCol, childCol); dsTaskActivities.Relations.Add(relTaskActivities); dgActivity.SetDataBinding(dsTaskActivities, "Tasks.TaskActivities"); This works fine. I have a properly behaving master detail relationship.
2
423
by: ruca | last post by:
Hi, I have a master and a detail datagrid. I put detail grid showing insise of a column of master grid. The problem is that it's not what I really want. What I really want would be that the detail grid appears between rows of master grid, i.e., when I select one record in master grid that detail grid appears between the selected row and next row. I know that the reason why my detail grid is show in one master column it's because I...
0
2006
by: hlam | last post by:
Help - Calculating the total of a column in a data grid -- when data grid is part of Master-Detail set-up I have setup a Master-Detail form using Visual Studio.Net. A ListBox is the (Master) and contains a list of dates. The data grid (Details portion) contains the details for a selected date (namely, a list of work codes and hours spent). I am trying to total the number of hours in the datagrid
7
1520
by: erniej | last post by:
as per instructions in the walkthrough, I have managed to create a master/detail relationship between two datagrids. However I have a requirement to apply this to three datagrids and the third datagrid does not seem to reflect the selected row on the second datagrid using this method. The relevant lines of code are as follows. ' binding on master table dgTables.SetDataBinding(CurrentViewDS,"ALL_TABLES")
6
5745
by: p.mc | last post by:
Hi all, I'm having major problems with a userControl which contains a datagrid. My problem concerns data binding. The Page_Load() procedure calls the DataBind procedure to bind the datagrid to a DataSet. If i include an if statement to prevent the data binding from occuring on a page PostBack in the following way:
3
1675
by: no | last post by:
Hi all, I have a dataset that contain 2 tables and a relationship between them (master detail). I bind this dataset to a form that include some textboxes that bind to the parent record, and a datagrid that is binded to the detailed records. Here is the code: Code:
2
1677
by: Michael D. Reed | last post by:
I have 2 list boxes and a combo box that are bound to table adaptors. I have another table that has relations with the underlying tables to the adaptors above. I have set this up in a dataset. How do I get to this relationship so I can bind a data grid to it? If I have only one list box and a grid, it is provided by intelligence-sense. Is it possible to have several list boxes/combo boxes and control a gird? I am using NET 2.0. Has...
7
4539
by: john | last post by:
In my form I have a master table and a details table linked 1xM. I can search through the whole parent table but I also like to be able to search through the child table fields to find parent records. Should I design a new form for this or can I somehow make this work in the same form. Thanks in advance, john
0
9632
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
9471
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10136
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...
0
8958
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6723
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5372
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
5501
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4036
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
3
2867
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.