0

如何拥有一个包含数据库中特定列的所有值的组合框。我有一个名为的列StudentName,我想要一个包含所有值的组合框StudentName

sql = new SqlConnection(@"Data Source=PC-PC\PC;Initial Catalog=Anbar;Integrated Security=True");
adapter = new SqlDataAdapter("select * from School", sql);

我应该如何继续?请提供一些代码以继续这些代码,任何帮助将不胜感激。

4

2 回答 2

5
sqlCon = new SqlConnection(@"Data Source=PC-PC\PC;Initial Catalog=Anbar;Integrated Security=True");
  SqlDataAdapter da = new SqlDataAdapter("Select StudentName from School", sqlCon);
        DataTable dt = new DataTable();
        da.Fill(dt);
        yourComboBox.DataSource = dt;
        yourComboBox.DisplayMember = "StudentName";
        yourComboBox.ValueMember = "StudentName";

还要在 ComboBox 中从数据库中读取此填充日期

于 2012-05-03T07:11:35.430 回答
1

使用以下代码

SqlDataAdapter da = new SqlDataAdapter("Select StudentName from School", sqlCon);
DataTable dat = new DataTable();
da.Fill(dat);
cmb.DataSource = dat;
cmb.DisplayMember = "StudentName";
cmb.ValueMember = "StudentName";
于 2012-05-03T07:21:41.803 回答