无限分类删除,谢谢

TaoTaoYou 2008-09-17 08:44:32
数据库:Access

表结构:

ID Parent_ID
1 0
2 1
3 1
4 2
5
6

现在我要删除ID为1的根目录,怎么把他的所有子类全部删除,最好给个实例代码,数据库是Access 谢谢
...全文
157 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
TaoTaoYou 2008-09-17
  • 打赏
  • 举报
回复
我倒了,大哥给个实现的函数吧,你这样实现不了具体功能,
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 TaoTaoYou 的回复:]
引用 1 楼 chinmo 的回复:
VBScript codeconn.execute("delete * from table where Parent_ID=1")'先执行这一句
conn.execute("delete * from table where ID=1")'后执行这一锯



这个好像只支持二级吧,如果他有的下级是五层怎么弄,谢谢
[/Quote]

哈哈

忘记了

看你表的结构就直接写了

无限的就不能使用conn.execute了

应该是

set rs=这样 打开记录级的方式了

比如
sql="select * from table where Parent_ID=1"
rs.open sql,conn,1,3
if not rs.bof then
PID=rs("id")
rs.delete
rs.update
end if
sql="select * from table where Parent_ID="&pid
rs.open sql,conn,1,3
if not rs.bof then
PpID=rs("id")
rs.delete
rs.update
end if


我只是给例子,你自己根据思路去组织吧
大猫钓鱼 2008-09-17
  • 打赏
  • 举报
回复
用个递归可以解决,其实你可以把表结构再设计详细些,譬如加上个关联节点的字段。。。

待会有空帮你看看^_^
不耐烦 2008-09-17
  • 打赏
  • 举报
回复
打开所有表 删除Parent_ID =1 的
TaoTaoYou 2008-09-17
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 TaoTaoYou 的回复:]
引用 1 楼 chinmo 的回复:
VBScript codeconn.execute("delete * from table where Parent_ID=1")'先执行这一句
conn.execute("delete * from table where ID=1")'后执行这一锯



这个好像只支持二级吧,如果他有的下级是五层怎么弄,谢谢
[/Quote]



???
sy_binbin 2008-09-17
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 chinmo 的回复:]
VBScript codeconn.execute("delete * from table where Parent_ID=1")'先执行这一句
conn.execute("delete * from table where ID=1")'后执行这一锯
[/Quote]
哈哈
TaoTaoYou 2008-09-17
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 chinmo 的回复:]
VBScript codeconn.execute("delete * from table where Parent_ID=1")'先执行这一句
conn.execute("delete * from table where ID=1")'后执行这一锯
[/Quote]


这个好像只支持二级吧,如果他有的下级是五层怎么弄,谢谢
  • 打赏
  • 举报
回复
conn.execute("delete * from table where Parent_ID=1")'先执行这一句
conn.execute("delete * from table where ID=1")'后执行这一锯
toury 2008-09-17
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 toury 的回复:]

数据库:Access

表结构:

ID Parent_ID cPath ----- 分类路径,记录该品种的分类深度
1 0 0,1,
2 1 0,1,2,
3 1 0,1,3,
4 2 0,2,4,
5 2 0,2,5,

要删除ID为1的根目:
sql="DELETE FROM 分类 WHERE Instr(cPa…
[/Quote]
parentID是变量,承载你要删除的目录ID,就是你表结构中的字段ID的值
toury 2008-09-17
  • 打赏
  • 举报
回复

数据库:Access

表结构:

ID Parent_ID cPath ----- 分类路径,记录该品种的分类深度
1 0 0,1,
2 1 0,1,2,
3 1 0,1,3,
4 2 0,2,4,
5 2 0,2,5,

要删除ID为1的根目:
sql="DELETE FROM 分类 WHERE Instr(cPath,',"&parentID&",')>0"
TaoTaoYou 2008-09-17
  • 打赏
  • 举报
回复
自己动手,丰衣足食

Function Del_Class(id)

Sql="Select top 1 * From Class_Name Where Parent_ID="&id
Set Rs=Conn.Execute(Sql)
While Not Rs.Eof
if rs.eof then
Response.write"ok"
Response.End
end if

C_id=Rs("id")
Sql="Delete * From Class_Name Where Parent_ID="&id
Conn.Execute(Sql)
Del_Class(C_id)
Rs.MoveNext

Wend
End Function
测试通过

因为表的结构只能这样实现了,那位大哥有比这好的方法,可以给一个,谢谢,

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧