0

製品に関連付けられた 2 つのレベルのカテゴリとブランドを持つ製品カタログがあります。

次のようなテーブル:

製品 : 製品 ID | カテゴリ ID | ブランドID

カテゴリー : カテゴリーID | 親 ID | 画像(ビット)

私が必要とするのは、ブランドのページを閲覧しているときに、ストアド プロシージャを使用して、このブランドの下に既に追加されている製品に関連付けられているカテゴリの親であるすべての「親カテゴリ」を選択することです...そして、必ず画像列の値を取得してください

私が使ったもの

CREATE PROCEDURE [dbo].[GetBrandProductsCats]
@iLanguageID int,
@iBrandID int
As
Begin
SELECT C.Image, C.CategoryID, C.ParentID,CD.Title, CD.Summary, BrandID = @iBrandID
FROM Categories C
    Join CategoryData CD on C.ParentID = CD.CategoryID
WHERE C.CategoryID in 
    (SELECT Products.CategoryID  
     FROM Products 
     WHERE Products.BrandID = @iBrandID)

End
GO

これは実際には機能しましたが、画像列の値は親カテゴリのものではありません

何か案は ?疲れた原因が1つあればいいのに:)

よろしくお願いします

4

1 に答える 1

0

これが私と一緒に働くコードです:

SQL ストアド プロシージャの場合

CREATE PROCEDURE [dbo].[GetBrandProductsCats]
@iLanguageID int,
@iBrandID int
As
Begin
select C.CategoryID,C.ParentID, BrandID = @iBrandID, C.Image, CD.Title, CD.Summary from Categories C
Join CategoryData CD on C.CategoryID = CD.CategoryID
Join BrandsCategories BC on BC.CategoryID = C.CategoryID and  BC.BrandID = @iBrandID
Where C.ParentID=0 and C.Status=1 and CD.LanguageID=@iLanguageID
End
GO

コードの場合:

製品の猫を取得するために保管された親 ID を使用し、その画像をサブ猫用の関数にしました。

<asp:Repeater id="rpCats" runat="server" >
<ItemTemplate>
<a href="categories.aspx?pid=<%# DataBinder.Eval(Container.DataItem, "ParentID") %>&brandid=<%# DataBinder.Eval(Container.DataItem, "BrandID") %>"><%# DataBinder.Eval(Container.DataItem, "Title") %></a>
<%# DataBinder.Eval(Container.DataItem, "Summary") %>
<asp:Repeater id="rpSubCats" runat="server" DataSource='<%# GetSubCats(CInt(DataBinder.Eval(Container.DataItem, "ParentID")))%>'>
<ItemTemplate >
<a href='products.aspx?pid=<%# DataBinder.Eval(Container.DataItem, "ParentID") %>&cid=<%# DataBinder.Eval(Container.DataItem, "CategoryID") %>&brandid=<%# DataBinder.Eval(Container.DataItem, "BrandID") %>'><%# DataBinder.Eval(Container.DataItem, "Title") %></a>
</ItemTemplate>
</asp:Repeater>
<div id="tblPic" runat="server">
<asp:Image id="imgThumb" runat="server" Borderwidth="0" Width="70px"></asp:Image>
</div>
<asp:TextBox id="txtImage" runat="server" Visible="False" Text='<%# DataBinder.Eval(Container.DataItem, "Image") %>'></asp:TextBox>
<asp:TextBox id="txtID" runat="server" Visible="False" Text='<%# DataBinder.Eval(Container.DataItem, "ParentID") %>'></asp:TextBox>
</ItemTemplate>
</asp:Repeater>

ここに GetSubCats 関数があります

Public Function GetSubCats(ByVal intParentID As Integer) As DataView
If Request("brandid") <> "" Then
Dim objDB As New ProductsDB
Dim dsSubCats As New DataSet
objDB.daGetBrandProductsSubCats.SelectCommand.Parameters("@iParentID").Value = intParentID
objDB.daGetBrandProductsSubCats.SelectCommand.Parameters("@iLanguageID").Value = System.Configuration.ConfigurationManager.AppSettings("LanguageID")
objDB.daGetBrandProductsSubCats.SelectCommand.Parameters("@iBrandID").Value = Request("brandid")
objDB.daGetBrandProductsSubCats.Fill(dsSubCats)
Dim dvSubCats As DataView = dsSubCats.Tables(0).DefaultView
GetSubCats = dvSubCats
End If
End Function

ありがとうございました。

于 2013-01-16T17:40:09.120 に答える