将数据表中的字段添加到ComboBox控件

如题,以下是实现代码:

SqlConnection con = new SqlConnection("数据库连接");
            con.Open();
            DataSet ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter("select 表中的一个或多个字段 from 表", con);
            da.Fill(ds);
            comboBox1.DataSource = ds.Tables[0].DefaultView;
            comboBox1.DisplayMember = "表中的一个字段";

posted @ 2011-06-11 22:37  __陆杨  阅读(336)  评论(0编辑  收藏  举报