How to separate diffrent database values when they have the same name?
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='&开发者_Python百科lt;%#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)
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
....
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)
精彩评论