PC Review


Reply
Thread Tools Rate Thread

Display mutliple 1-1 tables in DataGrid?

 
 
=?Utf-8?B?dGJydW1tZWw=?=
Guest
Posts: n/a
 
      10th Jun 2005
I’ve read a number of article/books on ADO.NET and the DataGrid and nobody
seems to address displaying multiple tables at once (not master/detail).

I’ve got two tables that have a 1-1 relationship based on a primary key.
Basically, think of it as one logical record (Customer) with some data in
table 1 and other data in table 2. I have these loaded into a DataSet and I
have a relation defined between them.

However, I cannot find any way to make the DataGrid display data from both
tables at the same time. I want to see the following:

Name Address
John 663 Main
Sally 223 Oak


Where Name is coming from table 1 and Address is coming from table 2.

Is this possible with the DataGrid control(s)? (I can certainly look at
writing a custom display control but I’d hate to reinvent the wheel)


 
Reply With Quote
 
 
 
 
=?Utf-8?B?S2VsbHkgU3VtcmFsbA==?=
Guest
Posts: n/a
 
      10th Jun 2005
I don't believe you are going to be able to do it the way your are
explaining. You are wanting to set the DataGrid.DataSource = Table, right? To
get this to work, you are going to have to modify one of the tables to
contain a DataColumn with an Expression pointing to the other tables column
of interest.
TableA (A DataColumns)
TableB (B DataColumns)(A Expression DataColumns)

Here is a quote from the MSDN DataColumn.Expression property documentation:
PARENT/CHILD RELATION REFERENCING

A parent table may be referenced in an expression by prepending the column
name with Parent. For example, the Parent.Price references the parent table's
column named Price.

A column in a child table may be referenced in an expression by prepending
the column name with Child. However, because child relationships may return
multiple rows, you must include the reference to the child column in an
aggregate function. For example, Sum(Child.Price) would return the sum of the
column named Price in the child table.

If a table has more than one child, the syntax is: Child(RelationName). For
example, if a table has two child tables named Customers and Orders, and the
DataRelation object is named Customers2Orders, the reference would be:
Avg(Child(Customers2Orders).Quantity)


if you are using typed DataSets, this can be done using the GUI interface.

Not a magical solution, but one that is solved by a lot of typing.

"tbrummel" wrote:

> I’ve read a number of article/books on ADO.NET and the DataGrid and nobody
> seems to address displaying multiple tables at once (not master/detail).
>
> I’ve got two tables that have a 1-1 relationship based on a primary key.
> Basically, think of it as one logical record (Customer) with some data in
> table 1 and other data in table 2. I have these loaded into a DataSet and I
> have a relation defined between them.
>
> However, I cannot find any way to make the DataGrid display data from both
> tables at the same time. I want to see the following:
>
> Name Address
> John 663 Main
> Sally 223 Oak
> …
>
> Where Name is coming from table 1 and Address is coming from table 2.
>
> Is this possible with the DataGrid control(s)? (I can certainly look at
> writing a custom display control but I’d hate to reinvent the wheel)
>
>

 
Reply With Quote
 
=?Utf-8?B?dGJydW1tZWw=?=
Guest
Posts: n/a
 
      11th Jun 2005
Hmm. Not good.

First off, I do not have multiple children and the data is text so there is
no aggregate function that I can use in referencing the child item.

What I'd like to be able to do is set the DataGrid.DataSource = myDataSet
(which contains both tables) and then set up the grid columns like this:

Grid.Column[0].DataTable = "Customers"
Grid.Column[0].DataItem = "Name"
Grid.Column[1].DataTable = "CustomerNotes"
Grid.Column[1].DataItem = "Note"

Sadly, I don't think anyone thought of this when the DataGrid was being
developed.

So, the workaround (solution, I guess) I came up with is to add the columns
from table to the schema for table1 and then .Merge the second table into the
first so I end up with one table for the DataGrid. Then, when I need to save
the table 2 data, I take the table being displayed and delete the table1
schema (columns) from it and then write it. Works like a charm since both
tables use the same primary key and I never need to save table 1 (it's
static). Seems like a hack but I think writing a display control that
handled multiple tables/items would be more work :-)

Thanks


"Kelly Sumrall" wrote:

> I don't believe you are going to be able to do it the way your are
> explaining. You are wanting to set the DataGrid.DataSource = Table, right? To
> get this to work, you are going to have to modify one of the tables to
> contain a DataColumn with an Expression pointing to the other tables column
> of interest.
> TableA (A DataColumns)
> TableB (B DataColumns)(A Expression DataColumns)
>
> Here is a quote from the MSDN DataColumn.Expression property documentation:
> PARENT/CHILD RELATION REFERENCING
>
> A parent table may be referenced in an expression by prepending the column
> name with Parent. For example, the Parent.Price references the parent table's
> column named Price.
>
> A column in a child table may be referenced in an expression by prepending
> the column name with Child. However, because child relationships may return
> multiple rows, you must include the reference to the child column in an
> aggregate function. For example, Sum(Child.Price) would return the sum of the
> column named Price in the child table.
>
> If a table has more than one child, the syntax is: Child(RelationName). For
> example, if a table has two child tables named Customers and Orders, and the
> DataRelation object is named Customers2Orders, the reference would be:
> Avg(Child(Customers2Orders).Quantity)
>
>
> if you are using typed DataSets, this can be done using the GUI interface.
>
> Not a magical solution, but one that is solved by a lot of typing.
>
> "tbrummel" wrote:
>
> > I’ve read a number of article/books on ADO.NET and the DataGrid and nobody
> > seems to address displaying multiple tables at once (not master/detail).
> >
> > I’ve got two tables that have a 1-1 relationship based on a primary key.
> > Basically, think of it as one logical record (Customer) with some data in
> > table 1 and other data in table 2. I have these loaded into a DataSet and I
> > have a relation defined between them.
> >
> > However, I cannot find any way to make the DataGrid display data from both
> > tables at the same time. I want to see the following:
> >
> > Name Address
> > John 663 Main
> > Sally 223 Oak
> > …
> >
> > Where Name is coming from table 1 and Address is coming from table 2.
> >
> > Is this possible with the DataGrid control(s)? (I can certainly look at
> > writing a custom display control but I’d hate to reinvent the wheel)
> >
> >

 
Reply With Quote
 
=?Utf-8?B?dGJydW1tZWw=?=
Guest
Posts: n/a
 
      14th Jun 2005
I can't do that since these are being loaded from independent XML files.
Thanks for the response though -- I failed to mention these are not DB
queries.


"judes_75" wrote:

>
> write a join query which returns the column from the both tables.
> Specify the proper joins also.
>
> -Jude
>
>
> --
> judes_75
> ------------------------------------------------------------------------
> judes_75's Profile: http://www.msusenet.com/member.php?userid=2145
> View this thread: http://www.msusenet.com/t-1870527666
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Display DataGrid with 2 tables? Alex Microsoft Dot NET Framework Forms 0 26th Apr 2005 09:04 AM
How do I display data from 2 tables in a datagrid? Jon Bosker Microsoft C# .NET 4 15th Apr 2005 12:18 AM
display columns from 2 different tables in the same datagrid =?Utf-8?B?U2l0YXI=?= Microsoft Dot NET Framework Forms 5 9th Feb 2005 11:35 AM
mutliple tables in datagrid =?Utf-8?B?ank=?= Microsoft ADO .NET 3 8th Oct 2004 09:30 AM
Display columns from 2 tables in datagrid HELP!!!!!!!!!!! Lerp Microsoft ASP .NET 1 21st May 2004 02:41 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:41 PM.