读取数据库 动态生成树
绑定?你要的是数据集一次绑定的?
由于我项目中节点不定的复杂性,我是节点逐个生成,生成时逐个附加数据的
【jiatong1981】:
private bool FillTree()
{
try
{
this._mConn.ConnectionString = ConStrr;
string _sqlstrr = "select * from PsnInfo";
this._mDa = new SqlDataAdapter(_sqlstrr,this._mConn);
this._mDa.Fill(this._mDs,"PersonInfo");
for (int i = 0; i < _mDs.Tables["PersonInfo"].Rows.Count; i++)
{
string strtemp1,strtemp2,strtemp3;
strtemp1= _mDs.Tables["PersonInfo"].Rows[i]["PersonID"].ToString();
TreeNode parentRoot = new TreeNode(strtemp1);
string _strsql = "select * from PsnDetail where PersonID='" + strtemp1 + "'";
DataSet ds = new DataSet();
_mDa.SelectCommand.CommandText = _strsql;
_mDa.Fill(ds,"city");
for (int j = 0; j < ds.Tables["city"].Rows.Count; j++)
{
strtemp2 = ds.Tables["city"].Rows[j]["aa"].ToString();
parentRoot.Nodes.Add(new TreeNode(strtemp2));
}
this.treeView1.Nodes.Add(parentRoot);
}
return true;
}
catch(SqlException ex)
{
MessageBox.Show(ex.Message);
return false;
}
finally
{
this._mConn.Close();
}
}
读取数据库 动态生成树
浙公网安备 33010602011771号