我找到一段代码,但是我在编译时下面红色的行出错,我是菜鸟,不知道是什么原因,谁能告诉我?
private void bindtree(TreeNodeCollection Nds , string depid)
{
DataSet ds=bindds();//获取DataSet,具体代码略
DataView dv=ds.Tables["tree"].DefaultView;
dv.RowFilter="HiDepID="+depid;
TreeNode tn;
string strID;
foreach(DataRowView dr in dv)
{
strID=dr["DepID"].ToString();
if (strID!="")
{
tn=new TreeNode();
tn.ID=dr["DepID"].ToString();
tn.Text=dr["Name"].ToString();
Nds.Add(tn);
bindtree(Nds[Nds.Count-1].Nodes,strID);
}
}
}
}
}
附
数据库结构:
CREATE TABLE [dbo].[tbDep] (
[DepID] [smallint] IDENTITY (1, 1) NOT NULL ,
[DepName] [varchar] (50) NOT NULL ,
[HiDepID] [smallint] NULL ,
)
private void bindtree(TreeNodeCollection Nds , string depid)
{
DataSet ds=bindds();//获取DataSet,具体代码略
DataView dv=ds.Tables["tree"].DefaultView;
dv.RowFilter="HiDepID="+depid;
TreeNode tn;
string strID;
foreach(DataRowView dr in dv)
{
strID=dr["DepID"].ToString();
if (strID!="")
{
tn=new TreeNode();
tn.ID=dr["DepID"].ToString();
tn.Text=dr["Name"].ToString();
Nds.Add(tn);
bindtree(Nds[Nds.Count-1].Nodes,strID);
}
}
}