using System; using System.Data; using System.Data.SqlClient; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page { public void BindDataBase() { SqlConnection sqlCon = new SqlConnection(); sqlCon.ConnectionString = "Data Source=PC-201010301842;Initial Catalog=Student;Integrated Security=True"; SqlDataAdapter da=new SqlDataAdapter("select 学号,姓名 from info",sqlCon); DataSet ds = new DataSet(); da.Fill(ds,"info"); TreeNode tree1=new TreeNode("学生信息"); this.TreeView1.Nodes.Add(tree1); for(int i=0;i<ds.Tables["info"].Rows.Count;i++) { TreeNode tree2=new TreeNode(ds.Tables["info"].Rows[i][1].ToString()); tree1.ChildNodes.Add(tree2); for(int j=0;j<ds.Tables["info"].Columns.Count;j++) { TreeNode tree3=new TreeNode(ds.Tables["info"].Rows[i][j].ToString()); tree2.ChildNodes.Add(tree3); } }