标签:ali HERE json load return 连接数 nod == nec
private void Form1_Load(object sender, EventArgs e)
{
List<Regions> regions = GetRegions().Where(r => r.RegionPID == 0).ToList();
foreach (var item in regions)
{
TreeNode treeNode = new TreeNode();
treeNode.Text = item.RegionName;
treeNode.Tag = item.RegionID;
treeView1.Nodes.Add(treeNode);
GetTree(treeNode);
}
}
public void GetTree(TreeNode treeNode)
{
List<Regions> regions = GetRegions().Where(r => r.RegionPID == Convert.ToInt32(treeNode.Tag+"")).ToList();
foreach (var item in regions)
{
TreeNode tree = new TreeNode();
tree.Text = item.RegionName;
tree.Tag = item.RegionID;
treeNode.Nodes.Add(tree);
GetTree(tree);
}
}
public List<Regions> GetRegions()
{
using(SqlConnection sqlConnection=new SqlConnection("Password = sa; Persist Security Info=True;User ID = sa; Initial Catalog = DB0213; Data Source = 127.0.0.1"))
{
string sql = "select * from Regions";
using(SqlDataAdapter sqlDataAdapter=new SqlDataAdapter(sql, sqlConnection))
{
DataTable dt = new DataTable();
sqlDataAdapter.Fill(dt);
return JsonConvert.DeserializeObject<List<Regions>>(JsonConvert.SerializeObject(dt));
}
}
}
标签:ali HERE json load return 连接数 nod == nec
原文地址:https://www.cnblogs.com/LYYXXXX/p/10386140.html