PDA

Click to See Complete Forum and Search --> : Datagrid forum??


§tudz
Jan 30th, 2004, 03:44 PM
Hi,

I'm currently creating as forum using ASP.Net - VB
I have managed to produce the multiple forums, and the threads,

but its when you go into the threads, and you get the main post, then the replies.

I have used a datagrid to show all the information such as Avatar, poster details, message etc,

but I am not sure hwo I get the replies into the datagrid, I have selected all the reply data in my SQL statement so all the fields are ready to insert.

The problem is that if I put the the data into the Datagrid it wont show the information as another row?
so any ideas how I can do this?

Thanks,

hellswraith
Jan 30th, 2004, 05:39 PM
I am not sure what you are saying. What I did with my forums is get the topic, and unioned in SQL Server the replies. This returns one result set to bind to the datagrid. They are nothing special, but you can view them here:
www.variantx.com/vxforums/

§tudz
Jan 31st, 2004, 04:14 AM
from looking at your forum, mine is the same sort of set up.

you have the forums which go to the threads, and then the threads lead to the thread and its replies.

did you put your threads and replies into two different tables?

and if so how did you get the thread to appear as well as its replies?

Thanks

hellswraith
Jan 31st, 2004, 03:15 PM
That was what I was trying to explain. I have two tables, topic posts, and replies. What I do is select the topic post, and UNION the replies so one result set is returned to the dataset. I then bind the dataset to the grid. If you don't know what I am talking about when I say UNION, look in the SQL server help documents for UNION.

§tudz
Jan 31st, 2004, 05:38 PM
thanks,


[goes to find sql book] :D

§tudz
Jan 31st, 2004, 06:39 PM
ok, seeing that a Union is also called an outer join, can you have multiple union joins the same as inner joins? if so how?

hellswraith
Feb 1st, 2004, 09:59 AM
No, a union is not a join.

What it does, is take two result sets and makes them one result set. So, when you select the topic post, it will be in one result set, and when you select the reply post records, they will be in another. You need to union those to make just one recordset returned.

Here is my stored procedure:

CREATE PROCEDURE dbo.spVXGetTopicDetails
@TopicID int
AS

/* Get the topic post, along with the replies */
SELECT 'Topic' as 'Table', VX_Topics.TopicID, VX_Topics.UserName, VX_Topics.Title, VX_Topics.PostDate, VX_Topics.Message, VX_Users.EmailAddress, VX_Users.AllowToBeEmailed, VX_Users.PostCount, VX_Users.DateRegistered, VX_Users.Location, VX_Users.Signature FROM VX_Topics
JOIN VX_Users ON VX_Users.UserName = VX_Topics.UserName
WHERE VX_Topics.TopicID = @TopicID
UNION ALL
SELECT 'Reply' as 'Table', VX_Replies.ReplyID, VX_Replies.UserName, VX_Replies.Title, VX_Replies.PostDate, VX_Replies.Message, VX_Users.EmailAddress, VX_Users.AllowToBeEmailed, VX_Users.PostCount, VX_Users.DateRegistered, VX_Users.Location, VX_Users.Signature FROM VX_Replies
JOIN VX_Users ON VX_Users.UserName = VX_Replies.UserName
WHERE VX_Replies.TopicID = @TopicID ORDER BY PostDate
RETURN

§tudz
Feb 1st, 2004, 10:09 AM
right ok,

but how did you put it intot the datagrid? as binding it to it would just show the thread, then the reply then the thread then the next reply, wouldn't it?

§tudz
Feb 1st, 2004, 11:16 AM
thanks it works now, sorted it, thanks for the help