DataRelation

JCWEBHOST
JCWEBHOST used Ask the Experts™
on
Hey guys i have two tables one called menu and one called products.

in my menu table i have coloums

id
parent_id
title

and products table

id
menu_id
name

now i am building a menu and need to link the two tables

how can i?

i have this code in c# which only builds the menu for the menu table but now i need to attach the product name to the menu where the id of the menu table equal to products table.

        DataSet dsm = new DataSet();
        DataSet dsp = new DataSet();
        DataSet ds = new DataSet();

        dsm = query.QueryDataSet("select id, title, parent_id from menu");
        dsm.DataSetName = "Menus";
        dsm.Tables[0].TableName = "menu";

        dsp = query.QueryDataSet("select menu_id, p_name from products");
        dsp.DataSetName = "Products";
        dsp.Tables[0].TableName = "products";

        DataRelation relation = new DataRelation("ParentChild", dsm.Tables["menu"].Columns["id"], dsm.Tables["menu"].Columns["parent_id"], true);

        relation.Nested = true;
        dsm.Relations.Add(relation);

        xmlDataSource.Data = dsm.GetXml();
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Hi,
what error you are getting, can you pl. explain more?

Author

Commented:
no erorr i need the two table to join and display in my menu
Are you getting any value in "dsm.GetXml()"
If yes, then menu should be displayed.

Check more references:

http://www.codeproject.com/Articles/18304/Using-Data-Relation-with-Data-Table

http://www.dotnetjohn.com/articles.aspx?articleid=63

Author

Commented:
i am trying to join the two dataset but it not working?

        DataSet dsm = new DataSet();
        DataSet dsp = new DataSet();

        dsm = query.QueryDataSet("select id, title, parent_id from menu");
        dsm.DataSetName = "Menus";
        dsm.Tables[0].TableName = "menu";

        dsp = query.QueryDataSet("select menu_id as parent_id , p_name as title from products");
        dsp.DataSetName = "Products";
        dsp.Tables[0].TableName = "products";

        dsm.Tables.Add(dsp.Tables[0].Copy());

        DataRelation relation = new DataRelation("ParentChild", dsm.Tables["menu"].Columns["id"], dsm.Tables["menu"].Columns["parent_id"], true);

        relation.Nested = true;
        dsm.Relations.Add(relation);

        xmlDataSource.Data = dsm.GetXml();

Author

Commented:
i want to join the two dataset in one?

but this just add new table

dsm.Tables.Add(dsp.Tables[0].Copy());

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial