Experts
I have what's probably an easy problem for most of you. I have a form with a combobox that I'm trying to populate with data from a sql database. I have created a Data Source called Tickets and changed the desired column(number) to a combobox, then dragged it onto my form. However, when the form inilizes, the combobox only displays the first number from the database. I assumed the combobox would display every number contained within the database. Can anyone provide a demonstration in regards to populating a combobox from a specific columns of an SQL database?
Loading
manisha dinithiPosted Jan 15, 2011, 2:41 AM
Kirtan PatelPosted Mar 1, 2010, 9:20 PM
private void Form1_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True");
SqlCommand comm = new SqlCommand("select * from Table1",con);
SqlDataAdapter da = new SqlDataAdapter(comm);
DataTable dt = new DataTable();
da.Fill(dt);
comboBox1.DataSource = dt;
//Name of Column to be displayed
comboBox1.DisplayMember = "Username";
con.Close();
}