Hej Wickmark
Det här är inte hela svaret, men jag hade ett liknande problem som jag löste med hjälp av följande kod. Den är hämtad från:
Planet-Source
<%
' Syntax
' Submit a QUERYSTRING to deletecomments.asp, containing
' id=[message/commentid]
' This will delete the 'Comment ID' and any comments 'under it'
' =====================
' Recursive Delete
' =====================
' For threaded message boards, for example, to have a 'tree' effect,
' it's a fun idea to use a MessageID and ParentID type column to store
' data locations. This code will delete the MessageID and any that fall
' under it - a difficult task if you have several children ID responses.
' Hope this helps - look for a full threaded application later.
' Love,
' Tim
'-----------------------------------------------------------------------------------
' NOTE: If your ASP version doesn't support Split(), download this
' handy VB Code from PSC (with a little reformatting and love, it will work)
' http://www.pscode.com/xq/ASP/txtCodeId.11235/lngWId.1/qx/vb/scripts/ShowCode.htm
'-----------------------------------------------------------------------------------
'---------------------------------------
' Sample Data
'---------------------------------------
' CommentID ParentID Subject...
' 1 0 Topic
' 2 0 DifferentTopic
' 3 2 Re: DifferentTopic
' 4 2 Re: DifferentTopic
' 5 3 Re: Re: DifferentTopic
' 6 5 Re: Re: Re: DifferentTopic
' [auto] [0=top] [sample]
'---------------------------------------
' Simply replace CommentID with a type of UNIQUE message ID
' And ParentID with a the PARENT. Set all top-level topics as '0'.
'---------------------------------------
' Recursive thread delete
' Copyright © 2001 Tim Feeley
'---------------------------------------
' Sub: DeleteC(ID)
' Deletes the comment [ID].
'---------------------------------------
Sub DeleteC(ID)
Set DeleteC_Conn = Server.CreateObject("ADODB.Connection")
DeleteC_Conn.Open ("DSN=fspace")
Set DeleteC_RS = Server.CreateObject("ADODB.Recordset")
DeleteC_RS.Open "SELECT CommentID FROM Comments WHERE CommentID = " & ID, DeleteC_Conn, 3, 3
DeleteC_RS.Delete
DeleteC_RS.Close
Set DeleteC_RS = Nothing
DeleteC_Conn.Close
Set DeleteC_Conn = Nothing
End Sub
'---------------------------------------
' Function: ReturnList(ID)
' Returns a pipe(|) delimited
' list of comments with ID as
' their 'parent.'
'---------------------------------------
Function ReturnList(ID)
On Error Resume Next
set ReturnListConn = Server.CreateObject("ADODB.Recordset")
ReturnListConn.ActiveConnection = "DSN=fspace"
ReturnListConn.Source = "SELECT CommentID, ParentID FROM Comments WHERE ParentID = " & ID
ReturnListConn.Open
If ReturnListConn.EOF Then ReturnList = 0
ReturnList_Return = ""
While Not ReturnListConn.EOF
ReturnList_Return = ReturnList_Return & ReturnListConn("CommentID") & "\|"
ReturnListConn.MoveNext
Wend
' Strip the last \| from the end.
ReturnList = Left(ReturnList_Return, Len(ReturnList_Return) - 1)
ReturnListConn.Close
Set ReturnListConn = Nothing
End Function
'---------------------------------------
' Sub: DoIt(ID)
' Removes anything related to
' ID. This is the actual code.
'---------------------------------------
Sub DoIt(ID)
tempHitList = ReturnList(ID)
For parseloop = 0 to UBound(Split(tempHitList, "|"))
workingwith = Split(tempHitList, "|")(parseloop)
if workingwith <> "0" and workingwith <> "" then
For parseloop2 = 0 to UBound(Split(workingwith, "|"))
tmpHL = Split(workingwith, "|")(parseloop2)
DeleteC(tmpHL)
Call DoIt(tmpHL)
Next
end if
Next
End Sub
'---------------------------------------
' Set Variables
'---------------------------------------
' Target: The initial CommentID to remove.
Target = Request.QueryString("ID")
' Delete the actual target record.
Call DeleteC(Target)
' Search and recursive delete the rest.
DoIt(Target)
%>