c# - How to read and write DataGridView data to Sql Table -
i working on database system. in system user can search specific member using id. searching them filters datagridview results specific member.
private void button3_click(object sender, eventargs e) { datagridview1.readonly = false; using (sqlconnection con = new sqlconnection(constring)) { int id = convert.toint32(textbox1.text); con.open(); datatable findaaron = new datatable(); sqldataadapter adapt = new sqldataadapter("select * memberstable memberid =" + id, con); adapt.fill(findaaron); datagridview1.datasource = findaaron; con.close(); } }
this code filters datagridview results down 1 row table 'memberstable'. user can physically click on table cell , edit data as want. once finished hit 'save changes' button want save changes made, update source table , refill datagridview members, updated info. code have behind 'save changes' button @ moment.
try { //memberclass.updatemember(); this.memberstabletableadapter.update(maindatabasedataset.memberstable); datagridview1.refresh(); messagebox.show("details updated"); } catch { messagebox.show("an error has occured"); }
this unfortunately not update datagridview in form display updated data or save data has been edited sql table. have puzzled on few days , can't figure out i'm doing wrong. , appreciated.
actually there no connection seen between memberstabletableadapter
, adapt
or maindatabasedataset.memberstable
, findaaron
.
try following;
//get changed data datatable changes = findaaron.getchanges(); if (changes != null) { //update data adapt.update(changes); }
Comments
Post a Comment