A. McN
A. McN

Reputation: 31

My ListView is displaying duplicates

I am trying to allow a user of a buy and sell website to only be able to edit the products that they have put up for sale. I have got that, but the result is now that it shows duplicates. I am new to Stack Overflow and asp.net so apologies if I am not following the correct procedures.

 <asp:SqlDataSource ID="itemsjoin" runat="server"  ConnectionString = '<%$ConnectionStrings:itemsconnection%>' SelectCommand="SELECT itemsupdate.ID, itemsupdate.itemname, itemsupdate.price, itemsupdate.image, itemsupdate.description, itemsupdate.location, itemsupdate.productID, itemsupdate.userID, producttype.productname
             FROM producttype, users, itemsupdate                 
             WHERE ([userID] = @userID)">
     <SelectParameters>
         <asp:QueryStringParameter Name="userID" QueryStringField="userID" Type="Int32"/>
     </SelectParameters>
         </asp:SqlDataSource>

         <asp:ListView ID="itemsdisplay" runat="server"  DataSourceID = "itemsjoin" DataKeyNames="ID">

             <ItemTemplate>

                 <div class="col-md-4"> 
                     <div class="itemtext">
                 </br>
                 <asp:Label ID="itemname" runat="server" Text='<%# Eval("itemname") %>'></asp:Label></br>

                 <asp:Label ID="itemprice" runat="server" Text='<%# Eval("price") %>'></asp:Label>

                 <asp:HyperLink ID="itemhyperlink" runat="server" NavigateUrl='<%#"itemediting.aspx?itemid="+Eval("ID")%>'>

                    <div class="imgright">
                         <asp:Image ID="imagepic" runat="server" ImageURL='<%# "../../files/"+Eval("image") %>' width="200px" /></asp:HyperLink>
                     </div>

                     </div>

                 </div>
             </ItemTemplate>



         </asp:ListView>

Upvotes: 2

Views: 96

Answers (1)

Sajeetharan
Sajeetharan

Reputation: 222692

Just add DISTINCT in your query

SELECT  DISTINCT  itemsupdate.ID, itemsupdate.itemname, itemsupdate.price, itemsupdate.image, itemsupdate.description, itemsupdate.location, itemsupdate.productID, itemsupdate.userID, producttype.productname
             FROM producttype, users, itemsupdate                 
             WHERE ([userID] = @userID)

Upvotes: 3

Related Questions