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

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -