c# - Get category and sub-category name in ASP.NET -


i have tblcategories , tblproducts table. want category , sub-category name on products.aspx page using joins:

table

the code below isn't working correctly:

datatable dtproducts = system.getdatatable(@"select b.categoryname,           a.* tblproducts left join tblcategories b on          (a.subcategoryid=b.categoryid) order a.productid desc"); if (dtproducts.rows.count > 0) {     collectionpager1.datasource = dtproducts.defaultview;     collectionpager1.bindtocontrol = rpproducts;      rpproducts.datasource = collectionpager1.datasourcepaged;     rpproducts.databind(); } 

i guessing need 2 joins:

select p.*, c.categoryname, sc.categoryname subcategoryname tblproducts p left join      tblcategories c      on p.categoryid = c.categoryid left join      tblcategories sc      on c.subcategoryid = sc.cateogryid order p.productid desc; 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -