未处理的system.stackoverflowexception类型的异常出现在 system.data.dll 中
未处理的“System.StackOverflowException”类型的异常出现在System.Data.dll中。出现此异常的代码如下:publicstaticLi...
未处理的“System.StackOverflowException”类型的异常出现在 System.Data.dll 中。出现此异常的代码如下:
public static List<LevelInfo> GetSubLevel(LevelInfo level)
{
List<LevelInfo> list = new List<LevelInfo>();
using (SqlConnection conn = new SqlConnection(strconn))
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "select * from tb_Organization where pid=@id";
cmd.Parameters.Add(new SqlParameter("@id", level.Id));
conn.Open();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
int id = Convert.ToInt32(sdr["id"]);
int tpid = Convert.ToInt32(sdr["pid"]);
string name = Convert.ToString(sdr["name"]);
list.Add(new LevelInfo(id, tpid, name));
}
}
}
return list;
}
调用此方法的代码如下:
void LoadTree(TreeView treeView)
{
LevelInfo level = new LevelInfo();//
level.Id = 0;
TreeNode node = new TreeNode("root");
GetSubNode(node, level);
foreach (TreeNode subNode in node.Nodes)
treeView.Nodes.Add(subNode);
treeView.ExpandAll();
}
void GetSubNode(TreeNode pNode, LevelInfo pLevel)
{
List<LevelInfo> levelList = Level.GetSubLevel(pLevel);
List<TreeNode> nodeList = new List<TreeNode>();
foreach (LevelInfo level in levelList)
{
TreeNode node = new TreeNode(level.Name);
node.Tag = level.Id;//每个节点的数据库id
pNode.Nodes.Add(node);
nodeList.Add(node);
}
for (int index = 0; index < levelList.Count; index++)
{
GetSubNode(nodeList[index], levelList[index]);
}
}
注:
LevelInfo 为自定义的用于存储某一个级别的节点的信息的,属性有id(节点的编号)、pid(父节点的编号)、name(节点的名字)。开发软件为Microsoft Visual Studio 2005 展开
public static List<LevelInfo> GetSubLevel(LevelInfo level)
{
List<LevelInfo> list = new List<LevelInfo>();
using (SqlConnection conn = new SqlConnection(strconn))
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "select * from tb_Organization where pid=@id";
cmd.Parameters.Add(new SqlParameter("@id", level.Id));
conn.Open();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
int id = Convert.ToInt32(sdr["id"]);
int tpid = Convert.ToInt32(sdr["pid"]);
string name = Convert.ToString(sdr["name"]);
list.Add(new LevelInfo(id, tpid, name));
}
}
}
return list;
}
调用此方法的代码如下:
void LoadTree(TreeView treeView)
{
LevelInfo level = new LevelInfo();//
level.Id = 0;
TreeNode node = new TreeNode("root");
GetSubNode(node, level);
foreach (TreeNode subNode in node.Nodes)
treeView.Nodes.Add(subNode);
treeView.ExpandAll();
}
void GetSubNode(TreeNode pNode, LevelInfo pLevel)
{
List<LevelInfo> levelList = Level.GetSubLevel(pLevel);
List<TreeNode> nodeList = new List<TreeNode>();
foreach (LevelInfo level in levelList)
{
TreeNode node = new TreeNode(level.Name);
node.Tag = level.Id;//每个节点的数据库id
pNode.Nodes.Add(node);
nodeList.Add(node);
}
for (int index = 0; index < levelList.Count; index++)
{
GetSubNode(nodeList[index], levelList[index]);
}
}
注:
LevelInfo 为自定义的用于存储某一个级别的节点的信息的,属性有id(节点的编号)、pid(父节点的编号)、name(节点的名字)。开发软件为Microsoft Visual Studio 2005 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询