1个回答
展开全部
您好,您的if条件句ds2.Tables.Count != 0 有问题,你用select语句从数据库查询数据,放到DataSet中,即使从数据库中查询出来时空的,也会生成一个DataSet,所以你用这个条件就永远不会走到else里面。你可以把条件设置为:ds2.Tables[0].Rows.Count != 0这样试试,这样应该没问题了。
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
{
string s = TreeView1.SelectedNode.Text.ToString();
string value = DropDownList_Service.SelectedValue;
SqlServerDataBase sd = new SqlServerDataBase();
string s1 = "select User_ID from [db].[dbo].[User] where User_Name='" + s + "'";
DataSet ds1 = sd.Select(s1, sd.DBconn());
if (ds1.Tables[0].Rows.Count != 0)
{
int id = (int)ds1.Tables[0].Rows[0]["User_ID"];
String s2 = "select User_Name,a.User_ID from [db].[dbo].[User] as a,User_Service as b,Service where a.User_ID=b.User_ID and Leader_ID="
+ id + " and Service.Service_ID=b.Service_ID and Service_Name='" + value + "'";
DataSet ds2 = sd.Select(s2, sd.DBconn());
if (ds2.Tables.Count != 0)
{
foreach (DataRow row in ds2.Tables[0].Rows)
{
TreeNode n = new TreeNode(row["User_Name"].ToString(), row["User_ID"].ToString());
//n.PopulateOnDemand = true;
//n.SelectAction = TreeNodeSelectAction.Expand;
TreeView1.SelectedNode.ChildNodes.Add(n);
}
}
else
{
string s3 = "select Data_ID from [db].[dbo].[ data] as a,Service as b where User_ID=" + id + " and a.Service_ID=b.Service_ID "
+ "and Service_Name='" + value + "'";
DataSet ds3 = sd.Select(s3, sd.DBconn());
if (ds3.Tables[0].Rows.Count != 0)
{
foreach (DataRow row1 in ds3.Tables[0].Rows)
{
TreeNode n = new TreeNode(row1["Data_ID"].ToString(), "1");
//n.PopulateOnDemand = false;
//n.SelectAction = TreeNodeSelectAction.Expand;
TreeView1.SelectedNode.ChildNodes.Add(n);
}
}
}
}
}
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
{
string s = TreeView1.SelectedNode.Text.ToString();
string value = DropDownList_Service.SelectedValue;
SqlServerDataBase sd = new SqlServerDataBase();
string s1 = "select User_ID from [db].[dbo].[User] where User_Name='" + s + "'";
DataSet ds1 = sd.Select(s1, sd.DBconn());
if (ds1.Tables[0].Rows.Count != 0)
{
int id = (int)ds1.Tables[0].Rows[0]["User_ID"];
String s2 = "select User_Name,a.User_ID from [db].[dbo].[User] as a,User_Service as b,Service where a.User_ID=b.User_ID and Leader_ID="
+ id + " and Service.Service_ID=b.Service_ID and Service_Name='" + value + "'";
DataSet ds2 = sd.Select(s2, sd.DBconn());
if (ds2.Tables.Count != 0)
{
foreach (DataRow row in ds2.Tables[0].Rows)
{
TreeNode n = new TreeNode(row["User_Name"].ToString(), row["User_ID"].ToString());
//n.PopulateOnDemand = true;
//n.SelectAction = TreeNodeSelectAction.Expand;
TreeView1.SelectedNode.ChildNodes.Add(n);
}
}
else
{
string s3 = "select Data_ID from [db].[dbo].[ data] as a,Service as b where User_ID=" + id + " and a.Service_ID=b.Service_ID "
+ "and Service_Name='" + value + "'";
DataSet ds3 = sd.Select(s3, sd.DBconn());
if (ds3.Tables[0].Rows.Count != 0)
{
foreach (DataRow row1 in ds3.Tables[0].Rows)
{
TreeNode n = new TreeNode(row1["Data_ID"].ToString(), "1");
//n.PopulateOnDemand = false;
//n.SelectAction = TreeNodeSelectAction.Expand;
TreeView1.SelectedNode.ChildNodes.Add(n);
}
}
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询