Suppose I have a table with two columns, id and parent. If I want to delete an Id all the times that id shows as a parent need thier ids collected and the process repeated until all are deleted. I have tried everything. I really want the code to do the process.
<%
system2 = request.form("system2")
node2 = request.form("node2")
seperate = split(node2,",")
node = seperate (0)
two = seperate (1)
Sub DeleteC(ID)
Set DeleteC_Conn = Server.CreateObject("ADODB
.Connectio
n")
DeleteC_Conn.Open ("TT")
Set DeleteC_RS = Server.CreateObject("ADODB
.Recordset
")
DeleteC_RS.Open "SELECT id FROM " & system2 & " WHERE ID = " & node, 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.ActiveConne
ction = "TT"
ReturnListConn.Source = "SELECT ID, Parent FROM " & system2 & " WHERE Parent = " & ID
ReturnListConn.Open
If ReturnListConn.EOF Then ReturnList = 0
ReturnList_Return = ""
While Not ReturnListConn.EOF
ReturnList_Return = ReturnList_Return & ReturnListConn("ID") & "|"
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)
%>
Or maybe something simpler like
Dim conn, sql
Set conn = Server.CreateObject("ADODB
.Connectio
n")
'conn.open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.Mappath("db2.mdb") & ";"
conn.open "TT"
'creating a recordset
set rs = Server.CreateObject("ADODB
.Recordset
")
sub ATOMIC
sql = " Update " & system2 & " set id = 0 where id = " & ID
rs.open sql, conn
do While str = " select 0 from " & system2 & " where id = '0' and parent <> '0'" exisits
rs.open str
stp = " update " & system2 & " set paretn = '0' where id = '0' and parent <> '0'"
rs.open stp
loop
gol = " delete from " & system2 & " where id = 0"
rs.open gol
end sub
call atomic
%>
</body>
</html>
or
Set conn = Server.CreateObject("ADODB
.Connectio
n")
'conn.open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.Mappath("db2.mdb") & ";"
conn.open "TT"
'creating a recordset
set rs = Server.CreateObject("ADODB
.Recordset
")
stp = "delete from " & system2 & " where id = " & ID & ";"
rs.open stp, conn
do
sql = " Select id from " & system2 & " where parent = " & id
str = "delete from " & system2 & " where id = " & id
set irs = Server.CreateObject("ADODB
.Recordset
")
irs.open sql
id = irs("id")
response.write(id)
irs.close
loop
or changing the table like
system2 = request.form("system2")
node2 = request.form("node2")
hi = split(node2, ",")
ID = hi(0)
Set conn = Server.CreateObject("ADODB
.Connectio
n")
'conn.open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.Mappath("db2.mdb") & ";"
conn.open "TT"
'creating a recordset
set rs = Server.CreateObject("ADODB
.Recordset
")
sql = "ALTER DATABASE TT SET RECURSIVE_TRIGGERS ON GO CREATE TRIGGER trg_d_Tree ON" & system2 & "FOR DELETE AS IF @@rowcount = 0 RETURN DELETE FROM T FROM " & system2 & " AS parent JOIN deleted AS id ON parent = id GO"
str = "DELETE FROM " & system2 & " WHERE id = " & hi(0)
stp = "SELECT * FROM " & system2
rs.open str, stp, conn
%>
</body>
</html>
but none of these attempts will work.