建一个方法GetList(),返回值为list,些方法就是从数据库获得数据
再
Combobox1DataSource = GetList();
Combobox1DisplayMember = "显示字段名"
Combobox1ValueMember = "值字段名"comboBox的 SelectedIndexChanged事件
通过选择的项,到数据库中找到相应的数据
放入dataset中,在赋值给textBox
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("server=;database=MyBook;uid=sa;pwd=gb123");
string sql = "select from test where name='" + thiscomboBox1SelectedItemToString() + "'"; //根据选中的值到数据库找东西
conOpen();
SqlCommand cmd = new SqlCommand(sql, con);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
daFill(ds);
conClose();
thistextBox1Text = dsTables[0]Rows[0][2]ToString();
thistextBox2Text = dsTables[0]Rows[0][3]ToString();
}直接更改comboBox属性值:
comboBoxAutoCompleteMode = AutoCompleteModeSuggestAppend;
comboBoxAutoCompleteSource = AutoCompleteSourceListItems;
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)