Re: DataRelations and DataGrids

From: aualias (aualias_at_newsgroups.nospam)
Date: 09/21/04


Date: Tue, 21 Sep 2004 09:53:12 -0400

Hi Sijin,

I am still confused as to how this is used with a DataGrid. For example, if
I have two tables and want to display the data (forget about editing for
now):

Table1
name (char)
descriptionFK (int)

Table2 - lookup
id (int)
description (char)

Create the DataSet with the two tables - oDataSet.
Create a DataRelation LookupToMain.
Call dataGrid1.SetDataBindings(oDataSet, "Table1");

How do I display the description field as a column in the DataGrid that
displays data from Table1?

Are there any examples that you know of?

This cannot be difficult. I'm missing something here...

Thanks.

Alfredo

"Sijin Joseph" <sijinNOSPAMdotnet@hotmail.com> wrote in message
news:#d42774nEHA.2340@TK2MSFTNGP11.phx.gbl...
> Hi,
>
> Yes you can use a DataRelation for this purpose, you will need to define
> a DataRelation between your parent tables and child tables and then use
> the DataColumn.Expression property to set the value to the
> ParentRelations relevant field.
>
> This is the relevant documentation from the MSDN documentation of
> DataColumn.Expression property
>
> 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)
>
>
> Also check out these articles
>
>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtskcreatinglookuptableforlistboxorcomboboxcontrol.asp
>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbwlkCreatingLookupTableOnData-BoundWindowsForm.asp
>
> Sijin Joseph
> http://www.indiangeek.net
> http://weblogs.asp.net/sjoseph
>
> aualias wrote:
> > I have tables Junk and JunkLookup in a DataSet. Junk has an integer
field
> > junkType, which is a primary key into JunkLookup.
> >
> > Can I bind to Junk and use a DataRelation to display and update data in
a
> > DataGrid?
> > Is it better to do a join in the SQL?
> >
> > Ideally, I would like to copy the database relationships in the DataSet
that
> > I use on the client.
> >
> > Thanks.
> >
> > Alfredo
> >
> >
> >



Relevant Pages

  • Re: Replacing key values with their referenced data records
    ... parent tables and child tables and then use the DataColumn.Expression ... you must include the reference ... Additionally, once I can get it to display properly, I need ...
    (microsoft.public.dotnet.framework.windowsforms.databinding)
  • Re: GetParentRow(s) or GetChildRows?
    ... Orders & Order Details. ... Which table would you expect to be the Parent? ... Which table would you expect to be the Child? ... > Creates a DataRelation with a specified parent and child column, ...
    (microsoft.public.dotnet.general)
  • How to sort a DataGrid bound to a DataRelation?
    ... DataRelation defining the parent-child relationship between them. ... form, there is a DropDownList ComboBox bound to the parent table, ... rows from the child table. ... I can't use a DataView because ...
    (microsoft.public.dotnet.framework.windowsforms.databinding)
  • Re: GetParentRow(s) or GetChildRows?
    ... Thanks for your reply, Jay. ... Creates a DataRelation with a specified parent and child column, ...
    (microsoft.public.dotnet.general)
  • Re: Searching for parent in child-parent table
    ... Should the UNION ALL not be placed between the SELECT statements? ... SELECT UNION ALL DOC, Ch2 AS Child ... When a document is entered you indicate it's parent if it has one. ... such that I can then use it as a reference to get other information on ...
    (microsoft.public.access.queries)