you are not including the child count, try:
for (int i = 0; i < childPosts.Tables["Child"].Rows.Count; i++)
{
replies +=
ReplyCount((int)childPosts.Tables["Child"].Rows[i]["posID"],replies);
}
note: this is a very slow way to count. you should write a sql stored proc
to do it.
-- bruce (sqlwork.com)
"Sam Collett" <> wrote in message
news: oups.com...
> I am looping through a table to get the number of replies to a post on
> a discussion system. 'posID' is the primary key (i.e. thread id),
> 'posParent' is the parent thread. However, it only seems to go down one
> level (i.e. direct replies, but not replies of replies)
>
>
> private int ReplyCount(int Id, int replies) {
>
>
> SqlConnection SqlConn = new SqlConnection(SqlConnString);
>
>
> // get child posts SQL statement
>
>
> string SQL = "SELECT * FROM post WHERE posParent = @posId";
>
>
> SqlDataAdapter SqlDa = new SqlDataAdapter();
>
>
> // select command
>
>
> SqlDa.SelectCommand = new SqlCommand(SQL, SqlConn);
>
>
> // add sql parameter to select command
>
>
> SqlDa.SelectCommand.Parameters.Add(new SqlParameter("@posId", Id));
>
>
> DataSet childPosts = new DataSet();
>
>
> SqlDa.Fill(childPosts, "Child");
>
>
> // increment replies counter
>
>
> replies+=(int)childPosts.Tables["Child"].Rows.Count;
>
>
> if (childPosts.Tables["Child"].Rows.Count > 0) {
>
>
> for (int i = 0; i < childPosts.Tables["Child"].Rows.Count; i++)
>
>
> {
>
>
> ReplyCount((int)childPosts.Tables["Child"].Rows[i]["posID"],replies);
> }
>
>
> }
>
>
> return replies;
>
>
> }
>
|