views:

20

answers:

2

I Have a problem to get the right "Name" from the database, The result is the same on all the "Name". I get the information from the same stored procedure. Are there a way to specify witch name I look for? ex. Text='<%#Eval("tblBrand.Name") %>' Gets the name in tblBrand. But that dosent work.

<asp:Label ID="lblProductName" runat="server" Text='<%#Eval("Name") %>' CssClass="productHead" />

<asp:Label ID="lblModelName" runat="server" Text='<%#Eval("Name") %>' CssClass="productHead" />

<asp:Label ID="lblSubCategoryName" runat="server" Text='<%#Eval("Name") %>' CssClass="productHead" />

<asp:Label ID="lblBrandName" runat="server" Text='<%#Eval("Name") %>' CssClass="productHead" />



SELECT
    Product.ProductID, Product.Name, tblBrand.Name, SubCategory.Name, 
     tblModel.Name
FROM            Product INNER JOIN
                         tblBrand ON Product.BrandID = tblBrand.BrandID INNER JOIN
                         tblModel ON Product.ModelID = tblModel.ModelID INNER JOIN
                         SubCategory ON Product.SubCategoryID = SubCategory.SubCategoryID
WHERE        (Product.ProductID = @ProductID)
+2  A: 

Alias the columns so the data contract in unambiguous.

SELECT
    Product.ProductID,
    Product.Name AS ProductName,
    tblBrand.Name AS BrandName,
    SubCategory.Name AS SubCategoryName, 
    tblModel.Name AS ModelName 
....
gbn
+1  A: 

Typically I'd alias the fields in the query, then reference the aliases:

<asp:Label ID="lblProductName" runat="server" Text='<%#Eval("ProductName") %>' CssClass="productHead" />

<asp:Label ID="lblModelName" runat="server" Text='<%#Eval("ModelName") %>' CssClass="productHead" />

<asp:Label ID="lblSubCategoryName" runat="server" Text='<%#Eval("SubCategoryName") %>' CssClass="productHead" />

<asp:Label ID="lblBrandName" runat="server" Text='<%#Eval("BrandName") %>' CssClass="productHead" />



SELECT        Product.ProductID, Product.Name ProductName, tblBrand.Name BrandName, SubCategory.Name SubCategoryName, tblModel.Name ModelName
FROM Product INNER JOIN tblBrand ON Product.BrandID = tblBrand.BrandID INNER JOIN tblModel ON Product.ModelID = tblModel.ModelID INNER JOIN SubCategory ON Product.SubCategoryID = SubCategory.SubCategoryID WHERE (Product.ProductID = @ProductID)
Dave
That is a way to do it, but I have alot of stored Procedures to go through in that case. Are there no other way?
Nicklas
Oh, this time I read it right, nice, that way it works great! Thanks!
Nicklas