|
楼主 |
发表于 2015-5-29 14:40:05
|
显示全部楼层
private void shuaxinshu()
{
SqlConnection conn = new SqlConnection(conn_kai);
conn.Open();
string sql = string.Format("select PName from Pastern ");
SqlCommand comm = new SqlCommand(sql, conn);
SqlDataReader myr = comm.ExecuteReader();
while (myr.Read())
{
TreeNode tn = Pasteshudel.Nodes.Add(myr.GetString(0));
SqlConnection conn1 = new SqlConnection(conn_kai1);
conn1.Open();
string sql1 = string.Format("select pid from Pastern where PName='{0}'", myr.GetString(0));
SqlCommand comm1 = new SqlCommand(sql1, conn1);
SqlDataReader myr1 = comm1.ExecuteReader();
if (myr1.Read())
{
pid = myr1.GetInt32(0);
}
myr1.Close();
conn1.Close();
conn1 = new SqlConnection(conn_kai1);
conn1.Open();
sql1 = string.Format("select SName from Specialty where pid={0}", pid);
comm1 = new SqlCommand(sql1, conn1);
myr1 = comm1.ExecuteReader();
while (myr1.Read())
{
TreeNode ts=tn.Nodes.Add(myr1.GetString(0));
SqlConnection conn2 = new SqlConnection(conn_kai2);
conn2.Open();
string sql2 = string.Format("select sid from Specialty where SName='{0}'", myr1.GetString(0));
SqlCommand comm2 = new SqlCommand(sql2, conn2);
SqlDataReader myr2 = comm2.ExecuteReader();
if (myr2.Read())
{
sid= myr2.GetInt32(0);
}
myr2.Close();
conn2.Close();
conn2 = new SqlConnection(conn_kai1);
conn2.Open();
sql2 = string.Format("select CName from Class where sid={0}", sid);
comm2 = new SqlCommand(sql2, conn2);
myr2 = comm2.ExecuteReader();
while (myr2.Read())
{
ts.Nodes.Add(myr2.GetString(0));
}
myr2.Close();
conn2.Close();
}
myr1.Close();
conn1.Close();
}
myr.Close();
conn.Close();
}
这个是我 平常的 treeview 我想用三层来实现 ,但是我不知道 该怎么传节点
|
|