Monday, 15 September 2014

asp.net - Refresh ComboBox in Windows form with datasource retains value even when datasource is empty -



asp.net - Refresh ComboBox in Windows form with datasource retains value even when datasource is empty -

i have 2 comboboxes, cmbstud , cmbhostel. filled database binding datasource datatable. update, cmbstud updates accordingly. when update lastly record datatable empties, cmbstud still retains value. cmbhostel info bound alter index of cmbstud.

in form load event have code:

dim cmd new sqlcommand("select stud_id,name student_details stud_id not in (select stud_id student_details hostel_id!=0)", sqlcont.conn) dim dr sqldatareader = cmd.executereader dim dat new datatable dim j integer j = 0 dat.rows.count - 1 dr.read() next dat.load(dr) cmbstud.displaymember = "name" cmbstud.valuemember = "stud_id" cmbstud.datasource = new bindingsource(dat, nothing) dr.close() sqlcont.conn.close()

in btnhostel updating have next queries implemented , next code reload form refresh datasources:

"update hostel set in_use=in_use+1 hostel_id=@hostid" "update student_details set hostel_id=@hostid stud_id=@stud_id" frmallocatehostel_load(nothing, nothing)

cmbstud index alter evnt code:

dim sqcm5 new sqlcommand("select hostel.hostel_id,hostel.hostel_name hostel inner bring together student_details on student_details.gender = hostel.hostel_gender student_details.stud_id =" & cmbstud.selectedvalue.tostring & " ", sqlcont.conn) dim datreadr5 sqldatareader = sqcm5.executereader dim dt5 new datatable dim n integer n = 0 dt5.rows.count - 1 datreadr5.read() next dt5.load(datreadr5) cmbhostel.valuemember = "hostel_id" 'asign value & display fellow member b4 datasource avoid errors cmbhostel.displaymember = "hostel_name" cmbhostel.datasource = dt5

there similar questions: combobox has old value after clear(); however, don't address issue.

changing did trick:

dim b new bindingsource() b.datasource = dat cmbstud.datasource = b b.resetbindings(false)

asp.net vb.net combobox

No comments:

Post a Comment