我已将表单名称存储在数据库中。现在我想使用这些名称加载表单。这是我的表结构:
frmID, Item_Name, formName
这是我的代码:
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
//TreeNode node = treeView1.SelectedNode;
string item = Convert.ToString(treeView1.SelectedNode);
int index = item.IndexOf(" ");
if (index > 0)
item = item.Substring(index + 1);
//MessageBox.Show(item);
var selectedFRM = from Menu in dbdata.Menus
where Menu.Item_Name == item
select Menu;
foreach (var pick in selectedFRM.Take(1))
{
string sel = pick.Form_Name;
Assembly asm = typeof(Form).Assembly;
Type type = asm.GetType(sel);
string df = Convert.ToString(type);
MessageBox.Show(df);
AssemblyName assemName = asm.GetName();
MessageBox.Show(assemName.Name);
try
{
Form frmChk = (Form)Activator.CreateInstance(type);
frmChk.Show();
}
catch (Exception)
{
MessageBox.Show("Error in loading form");
}
// MessageBox.Show(sel);
}
uptoAssembly asm = typeof(Form).Assembly;
代码工作正常。如何使用数据库中的“formName”加载表单