How to show one-to-many relation in 2 DataGrids?

  • Thread starter Thread starter Luc Kumps
  • Start date Start date
L

Luc Kumps

Let's say I have three database tables, each one having 2 columns:

DOCUMENTS contains columns "DOC_ID" (autonumbered) and "Name" (string)
DOCU_KEY contains columns "DOC_ID" and "KEY_ID" (both indexed)
KEYWORDS contains KEY_ID (autonumbered) and "Keyword" (string)

It is set up this way to be able to assign multiple keywords to each
document, and to keep the database normalised.
Now I would like to display two DataGrids, one displaying a list of
documents, a second one displaying the keywords that have been assigned to
those documents. I would also like to be able to insert (using the '*' row)
documents in the first DataGrid, and to insert keywords in the second
DataGrid.
When a keyword is used for the very first time, a new record should be added
to the KEYWORDS table. The next time, a record will be added to the DOCU_KEY
table, the KEYWORDS table remaining untouched.

While I could do this very easily by having only two tables (Documents and
Keywords) by using a DataRelation, and using that relation as a source for
the second DataGrid (by specifying DataMember="Documents.KeywordRel"), I
can't figure out how to do it with three tables. I guess there's a
straightforward solution, since even the most simple normalised database
contains this kind of setup over and over...

Or should I keep writing lots of application code?

Any suggestions?
Is there a good book explaining this kind of stuff?

TIA,

Luc K
 
Now while I haven't done exactly what you want , I have
worked with the DataRelations and the way they work on
drilldown is:

Documents.1stRelation.2ndRelation.3rdrelation etc

where your 2ndrelation is between the 2nd and 3rd table.

I have used this when printing out datagrids that have
been drilled down, So in order to work my way back out of
drill downs when printing each Level of detail I work
back through the relations.

This should work as a DataGrid member

eg.

DataMember="Documents.KeywordRell,2ndRelationName"

I have ADO.Net by David Sceppa ISBN 0-7356-1423-7 which
is excellent for DataSets, DataTables, but is very weak
on the datagrid.

Have fun!
-----Original Message-----
Let's say I have three database tables, each one having 2 columns:

DOCUMENTS contains columns "DOC_ID" (autonumbered) and "Name" (string)
DOCU_KEY contains columns "DOC_ID" and "KEY_ID" (both indexed)
KEYWORDS contains KEY_ID (autonumbered) and "Keyword" (string)

It is set up this way to be able to assign multiple keywords to each
document, and to keep the database normalised.
Now I would like to display two DataGrids, one displaying a list of
documents, a second one displaying the keywords that have been assigned to
those documents. I would also like to be able to insert (using the '*' row)
documents in the first DataGrid, and to insert keywords in the second
DataGrid.
When a keyword is used for the very first time, a new record should be added
to the KEYWORDS table. The next time, a record will be added to the DOCU_KEY
table, the KEYWORDS table remaining untouched.

While I could do this very easily by having only two tables (Documents and
Keywords) by using a DataRelation, and using that relation as a source for
the second DataGrid (by specifying
DataMember="Documents.KeywordRel"), I
 
Back
Top