Comment as per article

Last post 07-05-2008 10:23 AM by saquib189. 4 replies.

Sort Posts:

  • Comment as per article

    07-04-2008, 1:34 PM
    • Loading...
    • saquib189
    • Joined on 07-04-2005, 4:09 AM
    • ujjain
    • Posts 234

    Hi, i have a listview control that i show user comments on it. i also post comment in my form so, it display the comments, but when i move to next article it display the same comment. i want to display the comments as per article. i have two tables in my database that shows article and comments, so i want to INNER JOIN the tables that shows comment as per article, i show u my sql connection with code.

    Comment sql connection:

    <asp:SqlDataSource ID="Games" runat="server"
              ConnectionString="<%$ ConnectionStrings:SecurityTutorialsConnectionString %>" SelectCommand="SELECT dbo.aspnet_Users.UserName, GameComment.Subject, GameComment.Body, GameComment.CommentDate From GameComment INNER JOIN dbo.aspnet_Users ON GameComment.UserId = dbo.aspnet_Users.UserId" />

    so, please help me to solve this.

    Thank you 

     

    saquib
    Filed under:
  • Re: Comment as per article

    07-05-2008, 7:16 AM
    Answer
    • Loading...
    • anas
    • Joined on 09-21-2006, 4:31 AM
    • Jerusalem
    • Posts 4,343

    saquib189:
    so i want to INNER JOIN the tables that shows comment as per article

    But your select query will show the comments for all articles,

    You must have a 1-M relation between the article and the comments table , because every article will have many comments ,

    so you must have the articleID as a foreign key in the comments table , then you can use this query

    SELECT dbo.aspnet_Users.UserName, GameComment.Subject, GameComment.Body, GameComment.CommentDate From GameComment INNER JOIN dbo.aspnet_Users ON GameComment.UserId = dbo.aspnet_Users.UserId where ArticleId=@ArticleId

    Also you need to pass the current articleId or the ArticleID parameter , if you used the query string to pass the articleID , then you can use the Query string parameter ,

        <asp:SqlDataSource ID="Games" runat="server" ConnectionString="<%$ ConnectionStrings:SecurityTutorialsConnectionString %>"
            SelectCommand="SELECT dbo.aspnet_Users.UserName, GameComment.Subject, GameComment.Body, GameComment.CommentDate From GameComment INNER JOIN dbo.aspnet_Users ON GameComment.UserId = dbo.aspnet_Users.UserId  where ArticleId=@ArticleId ">
            <SelectParameters>
                <asp:QueryStringParameter QueryStringField="ArticleId" Name="ArticleId" Type="int32" />
            </SelectParameters>
        </asp:SqlDataSource>
     
    Regards,

    Anas Ghanem| Blog
  • Re: Comment as per article

    07-05-2008, 9:26 AM
    • Loading...
    • saquib189
    • Joined on 07-04-2005, 4:09 AM
    • ujjain
    • Posts 234
    Gi, i used the following code

    <asp:SqlDataSource ID="Games" runat="server"

    ConnectionString="<%$ ConnectionStrings:SecurityTutorialsConnectionString %>" SelectCommand="SELECT dbo.aspnet_Users.UserName, GameComment.Subject, GameComment.Body, GameComment.CommentDate From GameComment INNER JOIN dbo.aspnet_Users ON GameComment.UserId = dbo.aspnet_Users.UserId INNER JOIN GameComment ON Game.Gameid = GameComment.Gameid WHERE GameComment.Gameid = @Game.Gameid">

    <SelectParameters>  (i,e, "Gameid" = myarticle id)

    <asp:QueryStringParameter QueryStringField="Gameid" Name="ArticleId" Type="int32" />

    </SelectParameters>

    </asp:SqlDataSource>

    but now it does'nt show any comment related to it.

    please help me to solve this.

    Thank you

    saquib
    Filed under:
  • Re: Comment as per article

    07-05-2008, 9:54 AM
    • Loading...
    • anas
    • Joined on 09-21-2006, 4:31 AM
    • Jerusalem
    • Posts 4,343

    Change where part to :

    WHERE GameComment.Gameid = @GameID">

    and the paramter to :

    <asp:QueryStringParameter QueryStringField="Gameid" Name="GameID" Type="int32" />

     

    Regards,

    Anas Ghanem| Blog
  • Re: Comment as per article

    07-05-2008, 10:23 AM
    • Loading...
    • saquib189
    • Joined on 07-04-2005, 4:09 AM
    • ujjain
    • Posts 234

    Hi, i'll show you my database structure:

    Game (article)

    GameComments

    Thank you

    saquib
    Filed under:
Page 1 of 1 (5 items)
Microsoft Communities
Page view counter