winforms - Add values to a combobox in c#.net from SQL Server -
tried few set of codes populating combobox table in sql server, no avail! combobox in windowsapplicationform.this code using
public void binddata1() {     myconnection prms = new myconnection();      using (sqlconnection con = prms.getconnection())     {         string query = "select countryname countries";          sqlcommand cmd = new sqlcommand(query, con);          sqldataadapter d = new sqldataadapter(query, con);         dataset dt = new dataset();         d.fill(dt);          combobox1.datasource = dt.tables[0];          combobox1.displaymember = "countryname";     } } the method called @ form load event, there no values in combobox @ runtime.
try using datatable instead of dataset.
datatable dt = new datatable(); d.fill(dt);  combobox1.datasource = dt;  combobox1.displaymember = "countryname"; 
Comments
Post a Comment