c# - Multiple push refresh button -
this code shows select query in listview.
on second push of button "refresh", duplicates result, , on third enter in catch "error".
i don't understand why second works (not because duplicate, works) , on third there error.
public void button1_click(object sender, eventargs e) { sqlcommand cm = con.createcommand(); cm.commandtext = "select * h_facturi_clienti"; try { sqldatareader dr = cm.executereader(); while (dr.read()) { listviewitem item = new listviewitem(dr["h_id"].tostring()); item.subitems.add(dr["serie"].tostring()); item.subitems.add(dr["numar"].tostring()); item.subitems.add(dr["id_partener"].tostring()); item.subitems.add(dr["data"].tostring()); item.subitems.add(dr["valoare"].tostring()); listview1.items.add(item); } } catch (exception) { statuslbl.text = "eroare "; } }
did forget clear listview before re-loading it?
listview1.items.clear(); //then load list
did forget close sqldatareader
after finish using?
dr.close();
Comments
Post a Comment