score:5

Accepted answer
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";

Also read this Populate Date from Database in a ComboBox

score:1

Use the following code

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";

More questions

More questions with similar tag