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:
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
Post a Comment