c#treeview连接server数据库动态生成树形目录
c#treeview连接server数据库动态生成树形目录.根据数据变化的,数据库里的内容变了,我的目录也得跟着变.点击目录显示当前内容.我这样写,怎么不能生成,还望那位高手指点,private void F_zonghe_Load(object sender, EventArgs e)
{
try
{
TreeNode tn1 = treeView1.Nodes.Add("建始县民政局档案管理系统");
//TreeNode Ntn2 = new TreeNode("eff");
//tn1.Nodes.Add(Ntn2);
string str = "SELECT DISTINCT ZZLBID,ZZLBName from ZZLBTable where ZZLBName = 1 ";//and sn in(" + all.Substring(0, all.Length - 1).ToString() + ")";
//SqlConnection My_con = new SqlConnection(SQLstr);
SqlDataAdapter objAdapterNode = new SqlDataAdapter(SQLstr, My_con);
DataSet My_DataSet = new DataSet();
My_DataSet.Clear();
objAdapterNode.Fill(My_DataSet, "ZZLBName");
DataTable dt = My_DataSet.Tables["ZZLBName"];
tn1.Nodes.Clear();
//建立根节点,遍历。
foreach (DataRow dr in dt.Rows)
{
TreeNode Root = new TreeNode();
Root.Text = dr["ZZLBName"].ToString();
tn1.Nodes.Add(Root);
//TreeView1.Nodes.add(Root);//建立根节点
string str = "SELECT UnitID,ZZClass from ComeFile_Base ";//where UnitID = " + dr["ZZLBID"].ToString() + "' and ComeFile_Base in (" + ZZLBName.Substring(0, ZZLBName.Length - 1).ToString() + ")" + "order by ZZLBID,UnitID";
SqlDataAdapter objAdapter = new SqlDataAdapter(str, My_con);
DataSet dsNode = new DataSet();
dsNode.Clear();
objAdapter.Fill(dsNode, "tempNode");
DataTable dtNode = dsNode.Tables["tempNode"];
//建立子节点,遍历。
foreach (DataRow drNode in dtNode.Rows)
{
TreeNode Node = new TreeNode();
Node.Text = drNode["ZZClass"].ToString();
//Node.Target = "mainbottom";
string Path = drNode["menu_addr"].ToString();
int menusn = Convert.ToInt32(drNode["ZZClass"].ToString());
Node.Name = "Transfer.aspx" + "?ZZClass=" + Path;
Root.Nodes.Add(Node);//建立子节点
}
}
}
catch(Exception edf)
{
MessageBox.Show(" 错误!('您没有可操作的菜单项,请与管理员联系!'); "+edf.Message );
}
//finally
//{
// if (My_con.State.ToString().Equals("Open")) My_con.Close();
//}