Query problem - returns no details.http://forums.asp.net/t/1788545.aspx/1?Query+problem+returns+no+details+Wed, 25 Apr 2012 05:22:54 -040017885454910212http://forums.asp.net/p/1788545/4910212.aspx/1?Query+problem+returns+no+details+Query problem - returns no details. <p>There is a problem with my selectcommand. It returns all the forums, not just the news ones. I triend to use Dinstinct but it didnt make&nbsp; a difference. The objective is to pull everything&nbsp; from the forum table that have the same Category (ForumName) but it is pulling ecerything in the forums table not just the ones with the session variable &quot;news&quot; or the date. Can I have some help with that. Here is the current code.</p> <p>Default.aspx</p> <p>&nbsp;</p> <pre class="prettyprint">&lt;asp:SqlDataSource ID=&quot;SqlDataSource1&quot; runat=&quot;server&quot; ConnectionString=&quot;&lt;%$ ConnectionStrings:RTConnectionString %&gt;&quot; SelectCommand=&quot;SELECT * FROM Forum Fm LEFT JOIN Menu mn ON Mn.MenuName =@MenuName LEFT JOIN Thread Td ON Td.ForumId = Fm.ForumId LEFT JOIN Post Pt ON Pt.ThreadId = Td.ThreadId and Pt.DateTime = @Dete &quot; &gt; &lt;SelectParameters&gt; &lt;asp:SessionParameter DefaultValue=&quot;News&quot; Name=&quot;MenuName&quot; SessionField=&quot;Category&quot; /&gt; &lt;asp:SessionParameter DefaultValue=&quot;1/1/2011&quot; Name=&quot;Dete&quot; SessionField=&quot;Dete&quot; /&gt; &lt;/SelectParameters&gt; &lt;/asp:SqlDataSource&gt;</pre> <p></p> 2012-04-01T08:38:49-04:004910256http://forums.asp.net/p/1788545/4910256.aspx/1?Re+Query+problem+returns+no+details+Re: Query problem - returns no details. <p>Sorry I am not an expert in sql Queries. Still I can say&nbsp; I don't see a WHERE clause to filter the Data selection..</p> 2012-04-01T09:48:50-04:004913615http://forums.asp.net/p/1788545/4913615.aspx/1?Re+Query+problem+returns+no+details+Re: Query problem - returns no details. <p>Look at your query:</p> <p>SELECT * FROM Forum Fm &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;LEFT JOIN Menu mn ON Mn.MenuName =@MenuName&nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;LEFT JOIN Thread Td ON Td.ForumId = Fm.ForumId &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;LEFT JOIN Post Pt ON Pt.ThreadId = Td.ThreadId and Pt.DateTime = @Dete</p> <p>The problem here is you aren't telling it to find stuff&nbsp;based on the variable new or the date.&nbsp;You need to write your query more like this:</p> <p>SELECT * FROM Forum Fm &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;LEFT JOIN Menu mn ON Mn.MenuName =@MenuName&nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;LEFT JOIN Thread Td ON Td.ForumId = Fm.ForumId &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;LEFT JOIN Post Pt ON Pt.ThreadId = Td.ThreadId and Pt.DateTime = @Dete <br> <em><strong>WHERE&nbsp;Td.Title =&nbsp;@News AND Pt.DateTime = @Date&nbsp;</strong></em></p> 2012-04-03T10:21:41-04:004915121http://forums.asp.net/p/1788545/4915121.aspx/1?Re+Query+problem+returns+no+details+Re: Query problem - returns no details. <p>I dont know where the @News and @Date fit in. Let me re-ellaborate. There are two session variables. @dete and @Category. @Category(eg Value= &quot;News&quot;), is a column in the Menu Table, and&nbsp;is there to compare that the data in the forum table and retrieve everything in the forum Table based on the Category value(eg.News), or MenuName from the Menu Table(The value &quot;News&quot; is a MenuName column in the Menu table). In addition to that we want to pull the ThreadTitle in the Thread Table that matches the specified ForumID with the Forum Name Value is @Category(eg. News). It is also supposed to pull the Last PostTime that matches the session variable @dete,&nbsp;and UserName of the last Post, of the specified thread, of the specified forum, of the specified MenuName(eg. &quot;News&quot;)</p> <p>&nbsp;</p> <p>Table Structure</p> <p>Users(UserId) <br> Menu(MenuId, MenuName, MenuDesc) <br> Forum(ForumId, MenuId, ForumName, ForumDesc) <br> Thread(ThreadId, ForumId, ThreadTitle,ThreadText, UserId, ThreadDate)<br> Post(PostId, ThreadId, PostText, PostDate, UserId)</p> <p>The objective is to pull information necessary to populate</p> <p>1. The forum Page (Menu, Forum, Thread, Post&nbsp;Table Data, where Forum.MenuId = Session[&quot;Category&quot;] and (Last) Post.PostDate = Session [&quot;dete&quot;]),</p> <p>2. The thread page (Thread Table Data(Except for ThreadText where&nbsp; Thread.ThreadId = Session[&quot;ThreadId&quot;] and (Last) Post.PostDate = Session [&quot;dete&quot;])</p> <p>3. The Post Page (Both Thread and associated Post data where Thread.ThreadId=Session[&quot;ThreadId&quot;] and Post.ThreadId =Thread.ThreadId)</p> 2012-04-04T05:56:07-04:004915145http://forums.asp.net/p/1788545/4915145.aspx/1?Re+Query+problem+returns+no+details+Re: Query problem - returns no details. <p>Do you&nbsp;want &nbsp;to get&nbsp;data selected &nbsp;for&nbsp;&nbsp;3 GridViews in three different pages? Please make it clear.</p> 2012-04-04T06:14:52-04:004915673http://forums.asp.net/p/1788545/4915673.aspx/1?Re+Query+problem+returns+no+details+Re: Query problem - returns no details. <p>Sorry, was giving more of a theory than exact details. So for the dates, I presume that would be your @Dete&nbsp;(referred to as @Date)&nbsp;and the menuname would be @Category (this was that @News I referred to).</p> 2012-04-04T11:10:07-04:004916615http://forums.asp.net/p/1788545/4916615.aspx/1?Re+Query+problem+returns+no+details+Re: Query problem - returns no details. <p>Yes there are three pages, One gridview for each.</p> 2012-04-04T19:31:07-04:004916721http://forums.asp.net/p/1788545/4916721.aspx/1?Re+Query+problem+returns+no+details+Re: Query problem - returns no details. <p>The query doesnt return any values, just the feilds(Column Titles).</p> 2012-04-04T20:57:49-04:004917064http://forums.asp.net/p/1788545/4917064.aspx/1?Re+Query+problem+returns+no+details+Re: Query problem - returns no details. <p>I have tried it in many combinations but it just does not produce any data, just the Column Names.</p> 2012-04-05T04:23:19-04:004917086http://forums.asp.net/p/1788545/4917086.aspx/1?Re+Query+problem+returns+no+details+Re: Query problem - returns no details. <p></p> <blockquote><span class="icon-blockquote"></span> <h4>bbcompent1</h4> <p></p> <p>Look at your query:</p> <p>SELECT * FROM Forum Fm &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;LEFT JOIN Menu mn ON Mn.MenuName =@MenuName&nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;LEFT JOIN Thread Td ON Td.ForumId = Fm.ForumId &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;LEFT JOIN Post Pt ON Pt.ThreadId = Td.ThreadId and Pt.DateTime = @Dete</p> <p>The problem here is you aren't telling it to find stuff&nbsp;based on the variable new or the date.&nbsp;You need to write your query more like this:</p> <p>SELECT * FROM Forum Fm &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;LEFT JOIN Menu mn ON Mn.MenuName =@MenuName&nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;LEFT JOIN Thread Td ON Td.ForumId = Fm.ForumId &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;LEFT JOIN Post Pt ON Pt.ThreadId = Td.ThreadId and Pt.DateTime = @Dete <br> <em><strong>WHERE&nbsp;Td.Title =&nbsp;@News AND Pt.DateTime = @Date&nbsp;</strong></em></p> <p></p> </blockquote> <p></p> <p>&nbsp;</p> <p>Here is the current Query</p> <p>&nbsp;</p> <p>SELECT * FROM Forum Fm&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br> LEFT JOIN Menu Mn ON Mn.MenuName <a href="mailto:=@Category">=@Category</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br> LEFT JOIN Thread Td ON Td.ForumId = Fm.ForumId&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br> LEFT JOIN Post Pt ON Pt.ThreadId = Td.ThreadId and Pt.PostTime = @dete &nbsp;<br> WHERE Fm.ForumName = @Category AND Pt.PostTime = @dete</p> <p>&nbsp;</p> <p>Please help.</p> 2012-04-05T04:41:18-04:004918174http://forums.asp.net/p/1788545/4918174.aspx/1?Re+Query+problem+returns+no+details+Re: Query problem - returns no details. <p>This join right here seems to be the problem:</p> <p>LEFT JOIN Menu Mn ON Mn.MenuName <a href="mailto:=@Category">=@Category</a></p> <p>@Category isn't a table so it doesn't know how to relate that properly. Try your query like this to see if you get something and then if you get results, we will debug this Menu table.</p> <p>SELECT * FROM Forum Fm, Menu Mn&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br> LEFT JOIN Thread Td ON Td.ForumId = Fm.ForumId&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br> LEFT JOIN Post Pt ON Pt.ThreadId = Td.ThreadId and Pt.PostTime = @dete &nbsp;<br> WHERE Fm.ForumName = @Category&nbsp;AND Md.Menuname = @Category&nbsp;AND Pt.PostTime = @dete</p> 2012-04-05T13:37:47-04:004918177http://forums.asp.net/p/1788545/4918177.aspx/1?Re+Query+problem+returns+no+details+Re: Query problem - returns no details. <p>Sorry, mistyped:</p> <pre class="prettyprint">SELECT * FROM Forum Fm, Menu Mn LEFT JOIN Thread Td ON Td.ForumId = Fm.ForumId LEFT JOIN Post Pt ON Pt.ThreadId = Td.ThreadId AND Pt.PostTime = @dete WHERE Fm.ForumName = @Category AND Mn.Menuname = @Category AND Pt.PostTime = @dete</pre> <p></p> 2012-04-05T13:40:42-04:004918266http://forums.asp.net/p/1788545/4918266.aspx/1?Re+Query+problem+returns+no+details+Re: Query problem - returns no details. <p>Then why do&nbsp; you combine them?</p> <p>Write 3 separate simple quries for each Datasource in each page.</p> <p>First you do it on Forum page.</p> <p>&nbsp;</p> 2012-04-05T14:25:01-04:004918610http://forums.asp.net/p/1788545/4918610.aspx/1?Re+Query+problem+returns+no+details+Re: Query problem - returns no details. <p></p> <blockquote><span class="icon-blockquote"></span> <h4>basheerkal</h4> <p></p> <p>Then why do&nbsp; you combine them?</p> <p>Write 3 separate simple quries for each Datasource in each page.</p> <p>First you do it on Forum page.</p> <p>&nbsp;</p> <p></p> </blockquote> <p></p> <p>&nbsp;I dont intend to combine them on one page. I am just trying to get some help on each query for each datasource.</p> 2012-04-05T19:22:55-04:004918616http://forums.asp.net/p/1788545/4918616.aspx/1?Re+Query+problem+returns+no+details+Re: Query problem - returns no details. <p><strong></p> <blockquote><span class="icon-blockquote"></span> <h4>bbcompent1</h4> </strong> <p></p> <p>Sorry, mistyped:</p> <pre class="prettyprint">SELECT * FROM Forum Fm, Menu Mn LEFT JOIN Thread Td ON Td.ForumId = Fm.ForumId LEFT JOIN Post Pt ON Pt.ThreadId = Td.ThreadId AND Pt.PostTime = @dete WHERE Fm.ForumName = @Category AND Mn.Menuname = @Category AND Pt.PostTime = @dete</pre> <p><strong></p> </blockquote> </strong> <p></p> <p></p> <p>Error message: The multi-part identifier &quot;Fm.ForumId&quot; could not be bound</p> 2012-04-05T19:38:54-04:004918658http://forums.asp.net/p/1788545/4918658.aspx/1?Re+Query+problem+returns+no+details+Re: Query problem - returns no details. <p>I dont understand why its not producing any data. The query seems sound.</p> 2012-04-05T20:44:02-04:004918769http://forums.asp.net/p/1788545/4918769.aspx/1?Re+Query+problem+returns+no+details+Re: Query problem - returns no details. <p>Again, the error msg in the query tester for the sqldatasource is</p> <p>Error message: The multi-part identifier &quot;Fm.ForumId&quot; could not be bound</p> <p>the query is</p> <pre class="prettyprint">SELECT * FROM Forum Fm, Menu Mn LEFT JOIN Thread Td ON Td.ForumId = Fm.ForumId LEFT JOIN Post Pt ON Pt.ThreadId = Td.ThreadId AND Pt.PostTime = @dete WHERE Fm.ForumName = @Category AND Mn.MenuName = @Category AND Pt.PostTime = @dete</pre> <p>Table structure</p> <p>Users&nbsp;&nbsp;&nbsp;(UserId) <br> Menu&nbsp;&nbsp; (MenuId, MenuName, MenuDesc) <br> Forum&nbsp; (ForumId, MenuId, ForumName, ForumDesc) <br> Thread (ThreadId, ForumId, ThreadTitle,ThreadText, UserId, ThreadDate) <br> Post&nbsp;&nbsp; &nbsp;(PostId, ThreadId, PostText, PostDate, UserId)</p> <p>The objective is to pull information necessary to populate</p> <p>1. The forum Page (Menu, Forum, Thread, Post Table Data, where Forum.MenuId = Session[&quot;Category&quot;] and (Last) Post.PostDate = Session [&quot;dete&quot;]),</p> 2012-04-06T00:32:28-04:004919543http://forums.asp.net/p/1788545/4919543.aspx/1?Re+Query+problem+returns+no+details+Re: Query problem - returns no details. <p>Could you post a few rows from each table so I can emulate your tables here? Then I'll be able to better work on this problem.</p> 2012-04-06T11:47:11-04:004919981http://forums.asp.net/p/1788545/4919981.aspx/1?Re+Query+problem+returns+no+details+Re: Query problem - returns no details. <p>&nbsp;</p> <p>MenuId varchar(50)&nbsp; MenuName varchar(50)&nbsp; MenuDesc nvarchar(MAX)</p> <table> <tbody> <tr> <td> <p>1</p> </td> <td>&nbsp;&nbsp;&nbsp; News</td> <td>&nbsp;&nbsp; News Headlines.</td> </tr> </tbody> </table> <p>ForumId&nbsp;varchar(50)&nbsp; MenuId&nbsp;nvarchar(50)&nbsp; ForumName&nbsp;varchar(50)&nbsp; ForumDesc&nbsp;varchar(MAX)&nbsp;</p> <table> <tbody> <tr> <td>1</td> <td>&nbsp;&nbsp; 1</td> <td>&nbsp;&nbsp; World News</td> <td>&nbsp;&nbsp; News&nbsp;that has International implications.</td> </tr> </tbody> </table> <p>ThreadId&nbsp;varchar(50)&nbsp;ForumId&nbsp;varchar(50)&nbsp;UserId&nbsp;varchar(50)&nbsp; ThreadName&nbsp;varchar(50)&nbsp; Views&nbsp;varchar(50)&nbsp; ThreadText&nbsp;varchar(150)&nbsp; IsApproved&nbsp;bit &nbsp;ThreadTime&nbsp;date&nbsp;</p> <table> <tbody> <tr> <td>1</td> <td>&nbsp;1</td> <td>&nbsp;&nbsp; f8a61143-a418-4dfe-8a82-&nbsp; e83a2e756abe</td> <td>&nbsp;&nbsp; Test News Thread</td> <td>1</td> <td>&nbsp;&nbsp; This is a test thread and it is the reason why this site so popular.</td> <td>&nbsp; True</td> <td>&nbsp;03/04/2012</td> </tr> </tbody> </table> <p>PostId&nbsp;varchar(50)&nbsp; ThreadId&nbsp;varchar(50)&nbsp; PostTime&nbsp;datetime&nbsp; PostApproved&nbsp;bit&nbsp; PostText&nbsp;varchar(150)&nbsp; UserId&nbsp;uniqueidentifier&nbsp;</p> <table> <tbody> <tr> <td>1</td> <td>&nbsp;&nbsp; 1</td> <td>&nbsp;&nbsp; 03/04/2012 12:00:00 AM</td> <td>&nbsp;&nbsp; True</td> <td>&nbsp;&nbsp; This is a test Post for the News Thread.</td> <td>&nbsp;&nbsp; f8a61143-a418-4dfe-8a82-e83a2e756abe</td> </tr> </tbody> </table> <p>UserId&nbsp;uniqueidentifier&nbsp;</p> <p>f8a61143-a418-4dfe-8a82-e83a2e756abe</p> <p>&nbsp;</p> 2012-04-06T17:04:21-04:004919984http://forums.asp.net/p/1788545/4919984.aspx/1?Re+Query+problem+returns+no+details+Re: Query problem - returns no details. <p>Ok, now how do you want this data to look exactly in each gridview?</p> 2012-04-06T17:05:43-04:00