Users Pricing

articles

home / developersection / articles / how to populate records in combobox
How to populate records in ComboBox

How to populate records in ComboBox

Anonymous User 6510 01 Aug 2010 Updated 17 Mar 2020

To populate ComboBox we have to add the values of DataRows to it.

Example
//connecting to database and copying record to DataAdapter
string strConnection = "Server=abc\\SQLEXPRESs;Database=Employee;Trusted_Connection=True";
            SqlConnection con = new SqlConnection(strConnection);
            con.Open();
            SqlDataAdapter da = new SqlDataAdapter("select * from employee", con);
            DataSet ds = new DataSet();
            da.Fill(ds, "Employee");
            DataTable dt = ds.Tables["Employee"];
            DataRow row;
 
//populating combobox.
 
            for (int i = 0; i < dt.Rows.Count; i++)
            {
//this will run for all rows present in table.                             
                row = dt.Rows[i];
 
//adding items to combobox one by one.
                cbID.Items.Add(row[0].ToString());
            }


How to populate records in ComboBox



I am a content writter !


2 Comments


Markdown for AI

A clean, structured version of this page for AI assistants and LLMs.

Open .md