我有一个TBLCATEGORIES
和一个TBLPRODUCTS
表。我想使用连接在 Products.aspx 页面上获取类别和子类别名称:
以下代码无效:
DataTable dtProducts = system.GetDataTable(@"Select b.CategoryName,
a.* from TBLPRODUCTS a LEFT JOIN TBLCATEGORIES b ON
(A.SubCategoryID=B.CategoryID) order by a.ProductID desc");
if (dtProducts.Rows.Count > 0)
{
CollectionPager1.DataSource = dtProducts.DefaultView;
CollectionPager1.BindToControl = rpProducts;
rpProducts.DataSource = CollectionPager1.DataSourcePaged;
rpProducts.DataBind();
}
答案 0 :(得分:0)
我猜你需要两个连接:
Select p.*, c.CategoryName, sc.CategoryName as SubCategoryName
from TBLPRODUCTS p left join
TBLCATEGORIES c
on p.CategoryId = c.CategoryId left join
TBLCATEGORIES sc
on c.SubCategoryId = sc.CateogryId
order by p.ProductID desc;