using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.Text; using System.Windows.Forms;
namespace WindowsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); }
private void button1_Click(object sender, EventArgs e) { string con = "Server = 10.72.128.xxx; Initial Catalog=QA;User ID=DV_User;PassWord=xxxxxx"; string cmd = "select * from TB_DIVISION";
SqlConnection thisConnect = new SqlConnection(con); \\连接数据库,简便期间,没有做异常处理
thisConnect.Open();
SqlDataAdapter thisAdapter = new SqlDataAdapter(cmd, thisConnect); DataSet thisDataSet = new DataSet(); thisAdapter.Fill(thisDataSet, "TB_DIVISION"); string rootNodeStr = thisDataSet.Tables["TB_DIVISION"].Columns[1].ColumnName; TreeNode rootNode = new TreeNode(rootNodeStr); treeView1.Nodes.Add(rootNode);
foreach (DataColumn thisCol in thisDataSet.Tables["TB_DIVISION"].Columns) { rootNode.Nodes.Add(thisCol.ColumnName);
}
thisConnect.Close(); } } }
|