我有三个数据表,其中代表学校系名的表departments其中有departmentid,departmentname,还有系下面的各个专业的表subjects,其中有subjectid,subjectname,departmentid,还有一个专业下面的班级的表class,其中有classid,classname,subjectid,如何实现系是第一级节点,专业是第二级节点,班级是第三级节点?
vs2005,mssqlserver2000
vs2005,mssqlserver2000
解决方案 »
- 一个sql函数转换为access中的语句
- 未将对象引用设置到对象的实例
- 方法参数只读特性在C#是不是不存在?为什么呢?
- 在VS2005的DataGridView的编辑列对话框里设置好了列, 但有时莫明其妙列顺序变了,导致程序出错. 这是不是VS2005的bug.
- 有关XPTable的设置以及事件问题
- GridView 顯示效果問題
- 怎样才能在点击一个窗体中关闭按钮的时候,不要释放窗体在内存中的资源
- 求教:怎么将文本框中的文字保存到一个已有内容的ini文件中去?
- 关于ListView的选择问题
- 软件开发到中后期,会有很多的方法和变量,如何管理?
- 第一次发贴请原谅
- csdn的树型目录框架结构是怎么做的呀
ArrayList child = new ArrayList();
string[] a = null; SqlConnection conn = new SqlConnection("server=.;database=db;uid=sa;password=");
conn.Open();
SqlCommand comm = new SqlCommand("select distinct [one] from [Table]", conn);
SqlDataReader dr = comm.ExecuteReader();
while (dr.Read())
{
string temp = dr.GetString(0);
//this.treeView1.Nodes.Add(temp);
parent.Add(temp);
}
dr.Close(); for (int i = 0; i < parent.Count; i++)
{
child.Clear();
//this.treeView1.Nodes.Add(parent[i].ToString());
SqlCommand comm2 = new SqlCommand("select distinct [two] from [Table] where [one]='" + parent[i].ToString() + "'", conn);
SqlDataReader dr2 = comm2.ExecuteReader();
while (dr2.Read())
{
string temp = dr2.GetString(0);
child.Add(temp);
}
dr2.Close();
TreeNode t = new TreeNode(parent[i].ToString());
//t.ImageIndex = -2;
this.treeView1.Nodes.Add(t);
for (int j = 0; j < child.Count; j++)
{
//t.Nodes.Add(child[j].ToString());
for (int r = 0; r < child.Count; r++)
{
//child2.Clear();
SqlCommand comm3 = new SqlCommand("select distinct [three] from [Table] where [one]='"+parent[i].ToString()+"' and [two]='"+child[j].ToString()+"'",conn);
string str = comm3.ExecuteScalar().ToString();
a=str.Split(',');
}
TreeNode t2 = new TreeNode(child[j].ToString());
t.Nodes.Add(t2);
for (int temp = 0; temp < a.Length; temp++)
{
TreeNode t3 = new TreeNode(a[temp].ToString());
t2.Nodes.Add(t3);
}
}
}
其中一级节点放在Parent里面,二级放在Child里面,三级放在a里面。LZ参考下