这是Menu表的结构:
MenuID MenuName    ParentID   Depth
int      varchar(50)  int        int 代码:
public class left : System.Web.UI.Page
{
protected Microsoft.Web.UI.WebControls.TreeView Treeview1;
DataSet ds=new DataSet(); private void Page_Load(object sender, System.EventArgs e)
{
SqlConnection CN = new SqlConnection();
try 
{
//初始化连接字符串
CN.ConnectionString="server=localhost;database=weboa;User ID=sa;password=";
CN.Open();
//添加命令,从数据库中得到数据
SqlCommand sqlCmd= new SqlCommand();
sqlCmd.Connection = CN;
sqlCmd.CommandText = "select * from Menu";
sqlCmd.CommandType = CommandType.Text ;
SqlDataAdapter adp = new SqlDataAdapter(sqlCmd);
adp.Fill(ds);
}
catch (Exception ex)
{
throw (ex);   
}
finally 
{
CN.Close();
}
//调用递归函数,完成树形结构的生成
AddTree(0, (TreeNode)null);
}

// 递归添加树的节点
public void AddTree(int ParentID,TreeNode pNode) 
{
DataView dvTree = new DataView(ds.Tables[0]);
//过滤ParentID,得到当前的所有子节点
dvTree.RowFilter =  "[PARENTID] = " + ParentID;
foreach(DataRowView Row in dvTree) 
{
if(pNode == null) 
{    
TreeNode Node = Treeview1.Nodes.Add(Row["MenuName"].ToString());
AddTree(Int32.Parse(Row["MenuID"].ToString()),Node);    //再次递归

else 
{   
TreeNode Node = pNode.Nodes.Add(Row["MenuName"].ToString());
AddTree(Int32.Parse(Row["MenuID"].ToString()),Node); //再次递归
}
}
}
} 错误信息:
(1)在程序中这一句“Treeview1.Nodes.Add(Row["MenuName"].ToString())”上,与“Microsoft.Web.UI.WebControls.TreeNodeCollection.Add(Microsoft.Web.UI.WebControls.TreeNode)”最匹配的重载方法具有一些无效参数。
(2) 程序中这句“Row["MenuName"].ToString”,参数“1” : 无法从“string”转换为“Microsoft.Web.UI.WebControls.TreeNode”