1. 绑定数据库的方法 SqlConnection con=new SqlConnection("server=(local);database=department;uid=sa;pwd=");con.Open();SqlCommand cm=new SqlCommand("select empID,empName from emp",con);SqlDataReader dr=cm.ExecuteReader();//绑定this.lbxEmp.DataSource=dr; //lbxEmp为ListBox对象this.lbxEmp.DataTextField="empName";this.lbxEmp.DataValueField="empID";this.lbxEmp.DataBind();dr.Close();con.Close(); 2. 使用集合添加 SqlConnection con=new SqlConnection("server=(local);database=department;uid=sa;pwd=");con.Open( );SqlCommand cm=new SqlCommand("select empID,empName from emp",con);SqlDataReader dr=cm.ExecuteReader( );while(dr.Read( ))con.Close( ); 3. 为DropDownList添加第一项 this.DropDepartment.Items.Insert(0,new ListItem("请选择部门")); 相关文章: 2022-12-23 2022-12-23 2022-12-23 2021-10-20 2021-06-12 2021-09-28