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

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -