Recently, I have been paying attention to a data layer mapping generation tool, which is the original code that it can be confused to automatically recognize the table in the database and the fields in the table. Simply look at its original code with ILDASM directly carefully. I finally understood
In fact, the code is not long, it is very simple.
private void button1_Click (object sender, System.EventArgs e) {OleDbConnection con = new OleDbConnection (); TreeNode root = new TreeNode ( "database"); try {con.ConnectionString = "Provider = SQLOLEDB.1; Integrated Security = SSPI; Persist Security Info = False; Initial Catalog = Northwind; Data Source =. "; con.Open (); DataTable dt = con.GetOleDbSchemaTable (OleDbSchemaGuid.Tables, new object [] {null, null, null," TABLE "}) ; // see all the fields in Mo Yes OLEDBDATAREADER READ = NULL; OLEDBCOMMAND CMD = NULL; TREENODE TND; For (int i = 0; i
}}}} Catch (Exception E1) {MessageBox.show (E1.MESSAGE);} finally {con?close (); this.treeView1.nodes.add (root);}}} Basically, some interface code, change Changed, the effect is as follows