treeview在删除一个节点纪录的时候,用什么样的sql语句
能把它的子节点纪录一并删除?

解决方案 »

  1.   

    how is your table defined?
      

  2.   

    id,        parentid,       context
    节点id     父节点id        节点
    1          0               xxxx
    2          1
    3          1
    4          1
    5          1
      

  3.   

    再者,
    如果在不同的表表1Sid  xx
    1
    2
    3表2
    ID  Sid  yy
    1    2
    2    2
    3    2
      

  4.   

    say your table is like thiscreate table tree (id int identity, parentid int, name varchar(10))put the following inside a stored procedurecreate proc DeleteNodes
    @id int
    as
    begindeclare @level int
    set @level = 1declare @child table(id int, level int)insert into @child (id, level) values (@id, @level)
    while @@ROWCOUNT > 0
    begin
      set @level = @level + 1
      insert into @child (id, level) 
         select id, @level from tree
         where  parentid in (select id from @child where level=@level-1)
    end delete from tree where id in (select id from @child)endthen doDeleteNodes 2  -- 2 is the id for the node you want to delete 
      

  5.   

    also seehttp://www.codeproject.com/cs/database/Trees_in_SQL_databases.asp
      

  6.   

    你在高级搜索里面输入TreeView就可以找到好多答案了
      

  7.   

    可以使用关系(Relation)啊
    级联删除
      

  8.   

    你建表,肯定有问题。表1里应该有个ID,再是sid。不然sid肯定不是唯一的,删除的时候就会出错,而如果有ID和sid 就可以确定一条记录,删除才不出错。在.asp代码里 sid旁边或者你点删除的旁边加个隐藏域<input id=hide_num type=hidden value=<%#DataBinder.Eval(Container.DataItem,"ID")%>>(可能要用到DATARELATION)在cs代码里执行两次 HtmlInputHidden hidenum=(HtmlInputHidden)dgd_Deci.Items[i].FindControl("hide_num");
    delete * from 表1 where sid=2 and id='"+hidenum.value+"'
    delete * from 表2 where sid=2 and id=2就应该可以的
      

  9.   

    表1ID  Sid  xx
    1    2
    2    2
    3    2表2
    ID  Sid  yy
    1    2
    2    2
    3    2