c#编程中与数据库连接的一个存储过程
1、首先实现数据库:建立名称为OrgManagerDB的数据库
建立表为Org的表,表格式如下:
组织节点编号 OrgId int 主键
组织父节点编号 ParentOrgId int
组织名称 OrgName Char(20) 不可为空
2、在treeview(树视图中)实现一个存储过程pro_DelOrg :当删除一个跟节点时,删除他所有的子节点
上面的存储过程我做不出来
希望看到贴的高手能帮帮我
我一定都给分,
急啊!~
由于题目不是太完整
其中的treeview界面我没有传上来
--------------------编程问答-------------------- 递归
--------------------编程问答--------------------
CREATE PROCEDURE DelOrg
@OrgId int
AS
declare @ParentOrgId int
delete from Org where OrgId=@OrgId
declare cs CURSOR for select ParentOrgId from Org where ParentOrgId=@OrgId order by OrgId
open cs
FETCH NEXT FROM cs into @ParentOrgId
while (@@fetch_status = 0)
begin
delete from Org where OrgId=@ParentOrgId
exec DelOrg @ParentOrgId
FETCH NEXT FROM cs into @ParentOrgId
end
CLOSE cs
DEALLOCATE cs
--------------------编程问答-------------------- 无限极分类,高清思路好解决 --------------------编程问答-------------------- 如果用的是orale数据库,那就简单多了(直接用connect by):
declare cs CURSOR for select ParentOrgId from Org where ParentOrgId=@OrgId order by OrgId
改成:
declare cs CURSOR for select OrgId from Org where ParentOrgId=@OrgId order by OrgId
--------------------编程问答-------------------- create table #temp(int id,int status);
CREATE PROCEDURE DelOrg
@OrgId int
AS
delete from Org where OrgId in ( select OrgId from Org connect by prior ParentOrgId =OrgId start with OrgId=@OrgId)
insert into #temp(id,status) values(@deleteId,0)
declare @id int
while(exists(select 1 from #temp where status=0)
begin
select @id = top 1 id from #temp where status = 0
insert into #temp(id,status) select @OrgId ,0 from tbl where parentOrgId=@id
update #temp set @status = 1 where id=@id
end
delete from tbl where orgId in (select id from #temp)
drop table #temp --------------------编程问答-------------------- 一楼和五楼的还是希望你们帮我解释一下
我要实现的就是当删除OrgName时删除ParentOrgId 和OrgId
用的是sql2005编写 --------------------编程问答-------------------- 第一次进来!请多多帮助! --------------------编程问答-------------------- 我喜欢用
CREATE PROCEDURE DelOrg
@OrgId int
AS
delete from Org where OrgId in ( select OrgId from Org connect by prior ParentOrgId =OrgId start with OrgId=@OrgId)
应该比游标快 --------------------编程问答-------------------- 这个看过一点,还不是很了解! --------------------编程问答-------------------- 问题都你们回答了 我怎么说呀! --------------------编程问答-------------------- 写得不错,看看
补充:.NET技术 , 组件/控件开发