我有这三个表 [ Orders, order_Items, order_comment ]
| -Orders- | | -Order_Items- | | -Order_comment- |
| order_id | | order_RegCode | | order_id |
| order_RegCode |
如您所见,这三个表通过 2 个唯一键关联在一起!order_id
和order_RegCode
。
ps:order_RegCode
不是主键,是字符串!
我想当我删除任何订单时order_id
,删除存储在另外两个表中的所有相关信息。但是当我使用 Do While 我得到error Operation is not allowed when the object is closed
.
请指导我。
该代码是:
Dim Order_ID
Order_ID = Int(Request.Form("ID"))
Set Conn = server.createobject("adodb.connection")
Conn.open StrConn
Set Rs = Conn.execute("SELECT * From orders WHERE order_id="& Order_ID &"")
If NOT Rs.EOF then
RegCode = Rs("order_RegCode")
'//== Delete Order
Set Rs = Conn.execute("Delete From orders where order_id = "& orderID &"")
'//== Delete All Comments Belong to Order
Set Rs = Conn.execute("Select * From order_comment where order_id = "& Order_ID &"")
If NOT Rs.EOF then
Do While NOT Rs.EOF
Set Rs = Conn.execute("Delete From order_comment where order_id = "& Order_ID &"")
Rs.MoveNext
Loop
End if
'//== Delete All Items Belong to Order
Set Rs = Conn.execute("Select * From order_items where order_code = '"& RegCode &"'")
If NOT Rs.EOF then
Do While NOT Rs.EOF
Set Rs = Conn.execute("Delete From order_items where order_code = '"& RegCode &"'")
Rs.MoveNext
Loop
End if
End if