写一个TreeView的数据库,还有TreeView控件全部显示控件里数据库父节点和子节点,请教!!
1个回答
展开全部
这是我做的一个点菜系统里的一部分,时间紧就没怎么修改,你看看吧!
private void frmDC_Load(object sender, EventArgs e)
{
this.Text = RName + "点/加菜";
TreeNode newnode1 = tvFood.Nodes.Add("锅底");
TreeNode newnode2 = tvFood.Nodes.Add("配菜");
TreeNode newnode3 = tvFood.Nodes.Add("烟酒");
TreeNode newnode4 = tvFood.Nodes.Add("主食");
SqlConnection conn = BaseClass.DBConn.CyCon();
conn.Open();
SqlCommand cmd = new SqlCommand("select * from tb_food where foodty='1'", conn);
SqlDataReader sdr = cmd.ExecuteReader();
while (sdr.Read())
{
newnode1.Nodes.Add(sdr[3].ToString().Trim());
}
sdr.Close();
cmd = new SqlCommand("select * from tb_food where foodty='2'", conn);
sdr = cmd.ExecuteReader();
while (sdr.Read())
{
newnode2.Nodes.Add(sdr[3].ToString().Trim());
}
sdr.Close();
cmd = new SqlCommand("select * from tb_food where foodty='3'", conn);
sdr = cmd.ExecuteReader();
while (sdr.Read())
{
newnode3.Nodes.Add(sdr[3].ToString().Trim());
}
sdr.Close();
cmd = new SqlCommand("select * from tb_food where foodty='4'", conn);
sdr = cmd.ExecuteReader();
while (sdr.Read())
{
newnode4.Nodes.Add(sdr[3].ToString().Trim());
}
sdr.Close();
cmd = new SqlCommand("select * from tb_Waiter",conn);
sdr = cmd.ExecuteReader();
while (sdr.Read())
{
cbWaiter.Items.Add(sdr["WaiterName"].ToString().Trim());
}
cbWaiter.SelectedIndex = 0;
sdr.Close();
cmd = new SqlCommand("select RoomZT from tb_Room where RoomName='"+RName+"'",conn);
/* string zt = Convert.ToString(cmd.ExecuteScalar());
if (zt.Trim() == "待用")
{
groupBox1.Enabled = false;
groupBox2.Enabled = false;
groupBox3.Enabled = false;
groupBox4.Enabled = false;
}*/
conn.Close();
GetData();
tvFood.ExpandAll();
}
private void frmDC_Load(object sender, EventArgs e)
{
this.Text = RName + "点/加菜";
TreeNode newnode1 = tvFood.Nodes.Add("锅底");
TreeNode newnode2 = tvFood.Nodes.Add("配菜");
TreeNode newnode3 = tvFood.Nodes.Add("烟酒");
TreeNode newnode4 = tvFood.Nodes.Add("主食");
SqlConnection conn = BaseClass.DBConn.CyCon();
conn.Open();
SqlCommand cmd = new SqlCommand("select * from tb_food where foodty='1'", conn);
SqlDataReader sdr = cmd.ExecuteReader();
while (sdr.Read())
{
newnode1.Nodes.Add(sdr[3].ToString().Trim());
}
sdr.Close();
cmd = new SqlCommand("select * from tb_food where foodty='2'", conn);
sdr = cmd.ExecuteReader();
while (sdr.Read())
{
newnode2.Nodes.Add(sdr[3].ToString().Trim());
}
sdr.Close();
cmd = new SqlCommand("select * from tb_food where foodty='3'", conn);
sdr = cmd.ExecuteReader();
while (sdr.Read())
{
newnode3.Nodes.Add(sdr[3].ToString().Trim());
}
sdr.Close();
cmd = new SqlCommand("select * from tb_food where foodty='4'", conn);
sdr = cmd.ExecuteReader();
while (sdr.Read())
{
newnode4.Nodes.Add(sdr[3].ToString().Trim());
}
sdr.Close();
cmd = new SqlCommand("select * from tb_Waiter",conn);
sdr = cmd.ExecuteReader();
while (sdr.Read())
{
cbWaiter.Items.Add(sdr["WaiterName"].ToString().Trim());
}
cbWaiter.SelectedIndex = 0;
sdr.Close();
cmd = new SqlCommand("select RoomZT from tb_Room where RoomName='"+RName+"'",conn);
/* string zt = Convert.ToString(cmd.ExecuteScalar());
if (zt.Trim() == "待用")
{
groupBox1.Enabled = false;
groupBox2.Enabled = false;
groupBox3.Enabled = false;
groupBox4.Enabled = false;
}*/
conn.Close();
GetData();
tvFood.ExpandAll();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询