Treeview Database primary key and foreign key.
i have database contains 2 tables. clients table , appointment table. each client has name, surname , id(primary key). in appointment table there id(foreign key references id(pk) in client table). populating treeview both client data , appointment data. want app link appointment node treeview client node in treeview contains same id. basically, select user in treeview , in node users information along child node contains users appointment information. eg
this current code :
using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.windows.forms; using system.data.sqlserverce; namespace menusql { public partial class menu : form { sqlceconnection conn = new sqlceconnection(@"data source = c:\sqlcom\mydatabase#1.sdf"); public menu() { initializecomponent(); } private void menu_load(object sender, eventargs e) { } private void button2_click(object sender, eventargs e) { try { conn.open(); messagebox.show("successful connection", "connection test", messageboxbuttons.ok, messageboxicon.information); conn.close(); } catch (sqlceexception ex) { messagebox.show(ex.message, application.productname, messageboxbuttons.ok, messageboxicon.error); } } private void button1_click(object sender, eventargs e) { conn.close(); treeview1.nodes.clear(); sqlcecommand pop = new sqlcecommand("select * client", conn); try { conn.open(); sqlcedatareader read = pop.executereader(); while (read.read()) { treenode node = new treenode(read["name"].tostring()); node.nodes.add(read["id"].tostring()); node.nodes.add(read["name"].tostring()); node.nodes.add(read["surname"].tostring()); treeview1.nodes.add(node); } conn.close(); } catch (exception ex) { messagebox.show(ex.message, application.productname, messageboxbuttons.ok, messageboxicon.error); } sqlcecommand pop1 = new sqlcecommand("select * appointment", conn); try { conn.open(); sqlcedatareader read = pop1.executereader(); while (read.read()) { treenode node = new treenode(read["date"].tostring()); node.nodes.add(read["id"].tostring()); node.nodes.add(read["date"].tostring()); treeview1.nodes.add(node); } conn.close(); } catch (exception ex1) { messagebox.show(ex1.message, application.productname, messageboxbuttons.ok, messageboxicon.error); } } } }
can create view , populate treeview based on view instead of on demand select statement.
chanmm
chanmm
Visual Studio Languages , .NET Framework > Visual C#
Comments
Post a Comment