Solved

Gridview SQLDatasource question

Posted on 2010-11-24
2
388 Views
Last Modified: 2012-05-10
I have a directory page on a members only site and I'm using a gridview to display the information but i'm having a problem with the displayed data.  There are 3 tables involved iwth the query 1 table is the members table that pulls the members information, and the other 2 i want to do a count on the # of times the member id shows up in one specific column.  The problem is that the page is displaying both count columns within the gridview as the multiplication of the 2 counts.  I'm not sure how to get the individual parts to show up and hope someone can let me know where my sql is wrong.
<asp:GridView ID="GridView1" runat="server" DataSourceID="sdsMember" AutoGenerateColumns="false">
                                    <Columns>
                                    <asp:BoundField ItemStyle-Font-Bold="true" DataField="MEMBER_SNAME" HeaderText="Nickname" ItemStyle-Width="150px" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle" HeaderStyle-Width="150" HeaderStyle-HorizontalAlign="Center" HeaderStyle-VerticalAlign="Top" />
                                    <asp:ImageField DataImageUrlField="MEMBER_PIC" HeaderText="Avatar" ItemStyle-Width="150px" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle" HeaderStyle-HorizontalAlign="Center" HeaderStyle-VerticalAlign="Top"></asp:ImageField>
                                    <asp:TemplateField ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle" HeaderStyle-HorizontalAlign="Center" HeaderStyle-VerticalAlign="Top" ItemStyle-Width="150" HeaderStyle-Width="150">
                                    <HeaderTemplate># Shit Talk Posts</HeaderTemplate>
                                    <ItemTemplate><asp:Label ID="shitPosts" runat="server" Text='<%#Eval("NUMPOSTS") %>'></asp:Label></ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:BoundField DataField="RECORD" HeaderText="Record" HeaderStyle-Width="150" HeaderStyle-HorizontalAlign="Center" HeaderStyle-VerticalAlign="Top" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle" />
                                    <asp:BoundField DataField="TRADECOUNT" HeaderText="# of Acquisitions" HeaderStyle-Width="150" HeaderStyle-HorizontalAlign="Center" HeaderStyle-VerticalAlign="Top" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle" />
                                    </Columns>
                                </asp:GridView>
                                <asp:SqlDataSource ID="sdsMember" runat="server"
                                    ConnectionString="<%$ ConnectionStrings:DBSFL %>"  
                                    SelectCommand="SELECT M.MEMBER_SNAME, M.MEMBER_PIC, '(' + Convert(varchar,M.MEMBER_WINS) + '-' + Convert(varchar,M.MEMBER_LOSSES) + '-' + Convert(varchar,M.MEMBER_TIES) + ')' AS RECORD, COUNT(P.SHIT_ID) AS NUMPOSTS, COUNT(A.ACQ_ID) AS TRADECOUNT, M.MEMBER_POINTS FROM MEMBER M, ACQUISITIONS A, SHITTALK P WHERE M.MEMBER_ID = A.MEMBER_ID AND M.MEMBER_ID = P.POST_MEMBER GROUP BY MEMBER_SNAME, MEMBER_PIC, MEMBER_WINS, MEMBER_LOSSES, MEMBER_TIES, A.MEMBER_ID, MEMBER_POINTS"></asp:SqlDataSource>

Open in new window

0
Comment
Question by:rondre
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 12

Accepted Solution

by:
HugoHiasl earned 500 total points
ID: 34211171
How about using subselects?

Replace the
    count(p.shit_id)
with
    (SELECT COUNT(*) FROM ShitTalk st WHERE st.MemberId = m.MemberId)

The same for other count. Remove the 2 tables from the main query and give the Member table in the mainquery the alias m.

0
 

Author Closing Comment

by:rondre
ID: 34213241
Thank you - i knew you could do the select statement within the select but wasn't sure how to link on the memberid field - worked great!
0

Featured Post

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question