C# 从数据库向父节点树视图添加子节点
我正在使用一个树状视图系统,该系统从我们拥有的数据库中加载信息。我试图找出如何根据数据库中的ID将子节点添加到父节点 IE:ID of main profile=1检查子配置文件,如果ID匹配,则将其作为子配置文件添加到主配置文件中。我在下面添加了我正在使用的代码。我可以毫无问题地加载父节点,但是我不能将子节点添加到父节点。应根据主sID是否与子项的m_Sysid匹配来添加子项,然后添加子项C# 从数据库向父节点树视图添加子节点,c#,winforms,treeview,C#,Winforms,Treeview,我正在使用一个树状视图系统,该系统从我们拥有的数据库中加载信息。我试图找出如何根据数据库中的ID将子节点添加到父节点 IE:ID of main profile=1检查子配置文件,如果ID匹配,则将其作为子配置文件添加到主配置文件中。我在下面添加了我正在使用的代码。我可以毫无问题地加载父节点,但是我不能将子节点添加到父节点。应根据主sID是否与子项的m_Sysid匹配来添加子项,然后添加子项 public void Main_Profile_Load() {
public void Main_Profile_Load()
{
string ConfigurationFile = @"C:\Profiles\cfg\verswitch.sdf";
SqlCeConnection conn = null;
try
{
using (conn = new SqlCeConnection("Data Source =" + ConfigurationFile + "; Password =****"))
{
conn.Open();
SqlCeCommand cmd = conn.CreateCommand();
cmd.CommandText = "select StoreID, StoreName, Children, ID from t_MainProfiles";
cmd.ExecuteNonQuery();
var reader = cmd.ExecuteReader();
while (reader.Read())
{
string sID = reader[0].ToString().Trim();
string sName = reader[1].ToString().Trim();
string sChild = reader[2].ToString().Trim();
string sSysID = reader[3].ToString().Trim();
TreeNode parent = new TreeNode();
parent.Text = sName+ " - "+sID;
treeView1.Nodes.Add(parent);
}
reader.Close();
MessageBox.Show("Main Profiles Loaded. Retrieved ");
}
}
catch
{
MessageBox.Show("Unable to locate Database");
System.Diagnostics.Process.GetCurrentProcess().Kill();
}
finally
{
conn.Close();
}
现在,她是子配置文件加载的代码
public void Sub_Profile_Load()
{
string ConfigurationFile = @"C:\Profiles\cfg\verswitch.sdf";
SqlCeConnection conn = null;
try
{
using (conn = new SqlCeConnection("Data Source =" + ConfigurationFile + "; Password =****"))
{
conn.Open();
SqlCeCommand cmd = conn.CreateCommand();
cmd.CommandText = "select StoreID, Name, m_ProfileID from t_SubProfiles where Enabled = 1";
cmd.ExecuteNonQuery();
var reader = cmd.ExecuteReader();
DataTable sprofile = new DataTable();
while (reader.Read())
{
DataRow row = sprofile.NewRow();
row["Storeid"] = (reader[0].ToString().Trim());
row["name"] = (reader[1].ToString().Trim());
row["mproID"] = (reader[2].ToString().Trim());
sprofile.Rows.Add(row);
}
reader.Close();
MessageBox.Show("Sub Profiles Loaded. Retrieved " + sprofile.Rows.Count);
}
}
catch
{
MessageBox.Show("Unable to locate Database ");
System.Diagnostics.Process.GetCurrentProcess().Kill();
}
finally
{
conn.Close();
}
}
我只是不知道如何把它们组合在一起 一个父母可以有多少个孩子?1,2,无限?这能有多深?孩子能生孩子吗?孩子数量不限,但孩子不能生孩子