c#
  • sql
  • asp.net
  • visual-studio
  • listview
  • 2016-04-17 11 views 2 likes 
    2

    私は、売り上げた商品を編集できるように、購入と売りウェブサイトのユーザーに許可しようとしています。私はそれを持っていますが、結果は重複を示すようになりました。私は正しい手順を踏襲していない場合は、スタックオーバーフローとasp.net謝罪するのは初めてです。私のListViewが重複を表示しています

    <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> 
    
    +0

    をDISTINCT追加し、私は残りの部分は無用である、SQLの部分にあなたのコードを下に取り除くために、あなたをお勧めします。あなたの質問にいくつかのヒントを与えるとして、あなたのSQLを改善しようとします。そこに参加すると、自動的に複数の行に同じ商品が表示されます(各ユーザーごとに、各項目の更新が行われます)。このリンクもチェックしてください。http://sqlblog.com/blogs/aaron_bertrand/archive/2009/10/08/bad-habits-to-kick-using-old-style-joins.aspx – Learner

    +0

    @Learnerありがとうございます。問題がどこにあるのかわからなかったので、なぜそこにたくさんあるのですか? –

    +0

    私は、あなたにすぐに解決策を与えないように助けたがっていることを理解してくれることを願っています(それはとにかくとても簡単でした)...そのような質問をするのに費やす時間は、小さな研究と学習あなた自身で – Learner

    答えて

    3

    ジャスト(良い)答えを得るためには、あなたのクエリに

    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) 
    
    +0

    魅力的な@sajeetharanのように働いた。私は学ぶべきことがたくさんある!とても有難い。 –

    関連する問題