SQL Server Performance

Select statement displays empty in asp.net 3.5 GridView

Discussion in 'SQL Server 2008 General Developer Questions' started by Terry Wingfield, Dec 9, 2010.

  1. Terry Wingfield New Member

    Hey Guys, i am new to all this and very much in need of some advice.

    I have constructed a SQL select statement that displays a basic forum structure interface I.E:

    Forum Name, Threads and LastPost

    But for some reason when i add the SQL statement to the SQLDataSource and then hook the SQLDataSource to a gridview it displays empty.

    I have had this working before, but through a serious of individual select statements that use hard coded values which is very ineffeicent.
    My Forums are fully functional, just needs a tidy up and adheres to todays standards.

    My SQL select statment as follows:
    ------------------------------------------------------------------------
    SELECT TOP (1) ThreadsTable.Subject, MessageTable.Author, MessageTable.Date, TopicTable_1.TopicTableID,

    (SELECT Description
    FROM TopicTable
    WHERE (TopicTableID = @TopicTableID)) AS Description,

    (SELECT Name
    FROM TopicTable AS TopicTable_2
    WHERE (TopicTableID = @TopicTableID)) AS Forums,

    (SELECT COUNT(*) AS Expr1
    FROM ThreadsTable AS ThreadsTable_1
    WHERE (TopicTableID = @TopicTableID)) AS Threads

    FROM TopicTable AS TopicTable_1 INNER JOIN
    ThreadsTable AS ThreadsTable ON TopicTable_1.TopicTableID = ThreadsTable.TopicTableID

    INNER JOIN
    MessageTable ON ThreadsTable.ThreadsTableID = MessageTable.ThreadsTableID

    WHERE (TopicTable_1.TopicTableID = @TopicTableID)

    ORDER BY MessageTable.Date DESC
    --------------------------------------------------------
    Is there anyway that this statement can be re-constructed just by using GROUP BY clause instead of the WHERE clause?

    I hope this can be rectified and Thanks in advance for the advice given.

    Regards

    Tez
  2. Luis Martin Moderator

    Have you found any solution?
  3. satya Moderator

    Just for verification, are you able to get any results when you execute this code against database from SQL Server Management studio/
  4. Terry Wingfield New Member

    Hey Guys,
    Sorry for the late reply, but i did manage to fix the problem.
    My first attempt at a professional website, it is simple but for me it felt very complex.
    www.digitdotnet.co.uk
    Regards
    Tez
  5. FrankKalis Moderator

    Thanks for the feedback. Good to hear you found a solution that solves the issue.
  6. Madhivanan Moderator

    [quote user="Terry Wingfield"]
    Hey Guys,
    Sorry for the late reply, but i did manage to fix the problem.
    My first attempt at a professional website, it is simple but for me it felt very complex.
    www.digitdotnet.co.uk
    Regards
    Tez
    [/quote]
    Why dont you post the solution so that others can know it?
  7. Terry Wingfield New Member

    Hi Madhivanan,
    I will be creating a complete solution on my website. "How to implement a simple online community(Forum) from start to finish"
    I would post it here but its outside the scope of this service.
    www.digitdotnet.co.uk
    please allow time for this URL to resolve, min of 3days: www.digitdotnet.co.uk/developers.aspx
    Regards
    Tez
  8. Terry Wingfield New Member

    Hey Guys,
    Well finally after initial problems i created my simple forums.
    So iv'e decided to create a tutorial on how to create a simple forum.
    www.digitdotnet.co.uk/developers.aspx
    Regards
    Tez
  9. satya Moderator

    Glad ot know you are able to function as expected, but I still see that your problem may exist to see whether you can obtain relevant information.

Share This Page