database in one table and one column data fetch in diffrent combobox

charlybones commented: bad forum post, impossible to guess what you want.. -1

Recommended Answers

All 2 Replies

???

This forum post is not very descriptive...

If you want to get data from one table of the database to a dataTable, and populate a comboBox with the data from one of the columns of the dataTable, then you can do:

DataTable table = new DataTable(); // get the members (new ones)           
            using (SqlConnection sqlConn = new SqlConnection("connString"))
            {
                using (SqlDataAdapter da = new SqlDataAdapter(@"SELECT * FROM MyTable", sqlConn))
                    da.Fill(table);
            }
            if (table.Rows.Count > 0)
            {
                comboBox1.DataSource = table;
                comboBox1.DisplayMember = "Column1"; //SelectedItem, write the name of the column you want to show in comboBox, like Name
                comboBox1.ValueMember = "Column2";//this will be a SelectedValue, like ID
            }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.