Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Gridview SQLDatasource question

Posted on 2010-11-24
2
Medium Priority
?
395 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
2 Comments
 
LVL 12

Accepted Solution

by:
HugoHiasl earned 2000 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Recursive SQL is one of the most fascinating and powerful and yet dangerous feature offered in many modern databases today using a Common Table Expression (CTE) first introduced in the ANSI SQL 99 standard. The first implementations of CTE began ap…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

971 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