access建表 id name context
001 a ...
002 b ...
001001 a1 ...
00102 a2 ...
a,d是treeview的根结点,a1,a2是a的子节点.以此类推....
怎样从数据库读取表并用treeview把节点name和context显示?
我在form中加了一个treeview和text(text显示context用)
下面是连数据库代码
private void Form1_Load(object sender, System.EventArgs e)
{
string cnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Documents
and Settings\\liuys\\My Documents\\db1.mdb;Persist Security Info=False";
OleDbConnection cn = new OleDbConnection(cnStr);
cn.Open();
string sqlStr = "SELECT * from 表1";
OleDbCommand cmd=new OleDbCommand(sqlStr,cn);
OleDbDataReader dr = cmd.ExecuteReader();
while(dr.Read())
{
if(dr["Num"].ToString().Length==3)
{
this.treeView1.Nodes.Add(dr["Name"].ToString());
//TreeNode root = new TreeNode(dr["Name"].ToString());
}
}
}
这样写只能把根结点显示出来,子节点还不知道怎么写,
望高手指点下.谢谢!