Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Gridview SQLDatasource question

Posted on 2010-11-24
2
Medium Priority
?
394 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 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

Give Your Engineering Team a Productivity Boost

Learn why container technology is so powerful and how it can provide your team with productivity gains and other benefits.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

721 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