如何在vb.net(MSSQL)中执行递归查询 [英] how to execute a recursive query in vb.net (mssql)

查看:98
本文介绍了如何在vb.net(MSSQL)中执行递归查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我想在vb.net(MSSQL Server作为数据库)中执行递归查询.我发现了如何在mssql中执行此操作(例如,在这里: MSSQL递归层次查询 [ ^ ]
),但如何在vb.net中称呼它?
我的桌子看起来像这样:

ID父母姓名
---- ---- ----
1 Null A
2 1 B
3 1 C
4 3 D
...

那么如何获取某个元素的每个子元素的ID?

谢谢

Hallo,

I want to perform a recursive query in vb.net (MSSQL Server as Database). I found out how to do it in mssql (e.g. here: MSSQL Recursive Hierarchial Query[^]
), but how can I call it in vb.net?
My table looks like this:

ID Parent Name
---- ---- ----
1 Null A
2 1 B
3 1 C
4 3 D
...

So how can I get the IDs of every child element of a certain element?

Thanks

推荐答案

function get_id(int p_id)
{
   execut this line----
     -> "select id from table_name where parent="+p_id+"";

  it will return a result set
   in while loop access all its ids
  while(rs.next())
  {
     get_id(rs(0));// it is call to the parent function
  }
}


通过这种方式,我们可以获得某个父元素的所有子元素


in this way we can get all child elements of a certain parent element


这篇关于如何在vb.net(MSSQL)中执行递归查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆