Id LId
1 0
2 1
3 2
4 3
5 0
6 5-- 输入的参数是Id,怎么返回他的根父级啊
--比如:输入4,返回1,输入3,返回1 输入6,返回5,输入5,返回5
解决方案 »
- 调用一个web服务,它返回的是一张图片,我该使用什么控件把这张图显示在我的winform里面?
- ASP.NET安装程序中如何修改web.config文件的内容?
- 求网络流量系统源代码
- 关于ASP.NET页面刷新问题
- 关于下载文件时长文件名的问题.如何修改HttpResponseHeaders的编码??
- datagrid 简单问题,急急!~~~~~~~~~~~~~~~我还是菜鸟,就剩下这分了,帮我!~~~~~~~~~
- 关于webservice部署的问题
- asp.net用jmail发送邮件的问题?
- 请教高手!
- 然后用LINKBUTTON建立超链接啊!急!
- 点击datagrid 某行取值问题
- 继续是前台动态绑定新闻图片的问题
4的父级是3,3的父级是2,2的父级是1, 4的根父级就是1,1没有父级,就是根父级
实现tree的做出来了,现在想根据一个Id找到根父级的Id,不知道该怎么写了
//ht.Add("子节点ID","父节点ID");
ht.Add(1,0);
ht.Add(2,1);
ht.Add(3,1);
ht.Add(4,1);
Response.Write(ht[2].ToString());
//显示的就是ID为2的父节点ID 为1
//表结构就按照那个弄吧
insert into #tb
select 1,0 union all
select 2,1 union all
select 3,2 union all
select 4,3 union all
select 5,0 union all
select 6,5 select * from #tbdeclare @ID int
set @ID=5
;with cte as(
select * from #tb where ID=@ID union all
select t.* from cte c inner join #tb t on t.id=c.lid
)
select top 1 id from cte order by id
create table #tb(id int,LId int)
insert into #tb
select 1,0 union all
select 2,1 union all
select 3,2 union all
select 4,3 union all
select 5,0 union all
select 6,5 declare @ID int
set @ID=4
;with cte as(
select * from #tb where ID=@ID union all
select t.* from cte c inner join #tb t on t.id=c.lid
)
select top 1 id from cte order by id
/*
1
*/