从数据库查找数据绑定到combox
using (SqlConnection con = new SqlConnection(@"Data Source=.;Initial Catalog=Calling;User ID=sa;Password=123"))
{
con.Open();
using (SqlCommand cmd = con.CreateCommand())
{
//从表tb_Department中查找departmentType字段的内容
string sql2 = "select departmentType from tb_Department";
cmd.CommandText = sql2;
SqlDataAdapter da = new SqlDataAdapter(cmd.CommandText, con);
DataSet ds = new DataSet();
da.Fill(ds);
DataTable dt = ds.Tables[0];
comboBox1.DataSource = dt;
comboBox1.DisplayMember = "departmentType"; //要显示的数据库的字段
}
con.Close();}