Populating ComboBox from SQL in C# -
i trying populate combobox sql when assign value member it, gives me following error
cannot explicitly convert int string
could me understand , correct mistake?
void fillcombo() { string query_select = "select * department"; datatable dt = dataaccess.selectdata(query_select); sqldatareader dr = dataaccess.selectdatareader(query_select); while (dr.read()) { string dpt_name = dr.getstring(1); int dpt_id = (int)dr.getvalue(0); combobox1.datasource = dt; combobox1.valuemember = dpt_id; // error here combobox1.displaymember = dpt_name; } }
you must assign name of column in datasource
(datatable
) valuemenmber
, displaymember
string, , don't need use while loop, :
void fillcombo() { string query_select = "select * department"; datatable dt = dataaccess.selectdata(query_select); combobox1.datasource = dt; combobox1.valuemember = "columnname_departmentid"; combobox1.displaymember = "columnname_departmentname"; }
Comments
Post a Comment