Re: Binding a grid to master/detail related datatables



anonymous,

You know his next post is going to be, "I used the SqlCommandBuilder 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" <anonymous@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:423648E4-5801-4C1F-A960-DD77927DE451@xxxxxxxxxxxxxxxx
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.HouseName,
Street.StreeName
FROM Person
JOIN Address ON Adress.AddrId = Person.AddrId
JOIN Street ON Sreet.StreetID = Address.StreetId


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!




.



Relevant Pages

  • RE: Recursive SQL query?
    ... I don't know if other database vendors support this. ... Subject: Recursive SQL query? ... You shouldn't really need to go recursing through a data ... key that references that same table's primary key. ...
    (perl.dbi.users)
  • RE: Expression Builder basic question on syntax / Or / how to incorpor
    ... it is always best to avoid unnecessary hits on the database. ... Use only the control name without the Me. ... runtime error on the textbox. ... This SQL query works, ...
    (microsoft.public.access.formscoding)
  • Re: Noob question on how to use an insert query in a command button
    ... in mm/dd/yyyy format (regardless of what your Short Date format have been ... Dim dbLocation 'Location of our Access database file ... Set objADO = CreateObject'Create an ADO connection ... objADO.Execute 'Execute this SQL query ...
    (microsoft.public.access.forms)
  • Re: cgi ordering a table with sql
    ... table, through the SQL query. ... often only values may be replaced by placeholders, ... the prepare should give the database ... implemented within the Perl layer instead of passing the prepared ...
    (perl.beginners)
  • Re: Binding a grid to master/detail related datatables
    ... then I will have to program the updating manually ... The above SQL Query should give you the data you need. ... Say I have three datatables that are linked ... parent table again for each row. ...
    (microsoft.public.dotnet.general)