treeview动态生成树的问题) 生成页节点出现问题
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataView dv = drv( "select * from tree_node0 ");
foreach (DataRowView dr in dv)
{
TreeNode tn = new TreeNode();
tn.Text = dr[ "tree_name "].ToString();
tn.Value = dr[ "tree_id "].ToString(); //tree_id是44444444-4444-4444-4444-44444444444类型的
tn.Expanded = false;
TreeView1.Nodes.Add(tn);
childnode(tn);
}
}
}
protected void childnode(TreeNode tn)
{
string second =Convert.ToString(tn.Value).ToString();
DataView dv = drv( "select * from tree_node1 where tree_id= "+second);
foreach (DataRowView dr in dv)
{
TreeNode tn_1 = new TreeNode();
tn_1.Text = dr[ "tree_name1 "].ToString();
tn_1.Value = dr[ "tree_id1 "].ToString();
tn_1.NavigateUrl = "ads.aspx "+dr[ "tree_id1 "].ToString();
tn.ChildNodes.Add(tn_1);
}
}
private DataView drv(string str)
{
String connstr = ConfigurationManager.ConnectionStrings[ "CSDN "].ToString();
SqlConnection conn = new SqlConnection(connstr);
SqlDataAdapter sda = new SqlDataAdapter(str, conn);
DataSet ds = new DataSet();
sda.Fill(ds, "table "); //错误提示:操作数类型冲突: uniqueidentifier 与 numeric 不兼容
return ds.Tables[ "table "].DefaultView;
=================
表 tree_node0(根节点)
字段 trss_name tree_id
表 tree_node1(叶节点)
字段 trss_name1 tree_id
我想用tree_id来标示 哪个页节点属于 那一个根节点
错误提示:
操作数类型冲突: uniqueidentifier 与 numeric 不兼容
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Data.SqlClient.SqlException: 操作数类型冲突: uniqueidentifier 与 numeric 不兼容
源错误:
行 56: SqlDataAdapter sda = new SqlDataAdapter(str, conn);
行 57: DataSet ds = new DataSet();
行 58: sda.Fill(ds, "table "); //错误指向58行
行 59: return ds.Tables[ "table "].DefaultView;
行 60:
-----------------------
调试的时候 跟节点已经添加完成但添加页节点报错
[解决办法]
sql 语句错误
DataView dv = drv( "select * from tree_node1 where tree_id= "+second);
DataView dv = drv( "select * from tree_node1 where tree_id= ' "+second+ " ' ");