My sql server Table is:-
User_Id Name
1 Prince
2 Rakesh
3 Rahul
Now my table name is Student
-----
In C# Windows application:-
Declare the page load event
SqlConnection con = new SqlConnection(
SqlDataAdapter adpter = new SqlDataAdapter("Select * from cUser", con);
DataSet ds = new DataSet();
adpter.Fill(ds);
comboBox1.DataSource = ds.Tables[0];
comboBox1.DisplayMember = "Name";
comboBox1.ValueMember = "User_Id";
In above solution ComboBox1 is my combobox
In another way of you use go to combobox and choose the datasource property and add project data source
now you select the displaymember property for which you want to display. also ValueMamber property use for display value.
3rd Method
SqlConnection con = new SqlConnection(
SqlDataAdapter adpter = new SqlDataAdapter("Select * from cUser", con);
DataSet ds = new DataSet();
adpter.Fill(ds);
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
comboBox1.Items.Add(ds.Tables[0].Rows[i][0].ToString());
}