combox.DataSource=返回的DataSet.Tables[0]
combox.DisplayMember="stuNO"
private void Form1_Load(object sender, EventArgs e){
String ConnectionString = "Server=.\\mysqlserverDataBase=demouid=sapwd=songhai111"
SqlConnection Connection = new SqlConnection(ConnectionString)//声明数据库链接
string SqlString = "select name from test order by id desc"//查询语句
DataSet dataset = new DataSet()//声明数据集
Connection.Open()//打开数据库
SqlDataAdapter adapter = new SqlDataAdapter(SqlString, Connection)
adapter.Fill(dataset)//读取数据放入数据集
Connection.Close()//关闭数据库
DataTable dt = dataset.Tables[0]//从数据集中取出表
comboBox1.DataSource = dt//下拉列表绑定查询的10条的数据表
comboBox1.DisplayMember = "name"//设置下拉显示的是month行的值
comboBox1.SelectedIndexChanged += new EventHandler(comboBox1_SelectedIndexChanged)
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
textBox1.Text = (comboBox1.SelectedValue).ToString()
string txt = this.comboBox1.Text
this.textBox1.Text = txt
}
}
其它功能你自己看着弄就行了
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)