Here is an example how i have done this recently:
using (SqlConnection connDB = new SqlConnection())
using(SqlDataAdapter adapter = new SqlDataAdapter())
{
connDB.ConnectionString = @"Server=SRV-WEB\SQLEXPRESS;Database=????;User Id=?????;Password=?????;";
adapter.SelectCommand = connDB.CreateCommand();
adapter.SelectCommand.CommandText = "SELECT [ConsultantID],[name] FROM [dbo].[ConsultantOptions] WHERE Enabled = 1 ORDER BY [name] ASC; ";
using(DataTable data = new DataTable())
{
adapter.Fill(data);
data.Rows.Add(new string[] { "0", "All" });
DataView view = data.AsDataView();
view.Sort = "name";
this.cboConsultantName.DataSource = view;
this.cboConsultantName.DataTextField = "name";
this.cboConsultantName.DataValueField = "ConsultantID";
this.cboConsultantName.DataBind();
this.cboConsultantName.SelectedValue = "All";
}
}
To reference the ID value I would use the following line:
this.cboConsultantName.SelectedItem.Value