c# - Updating records from Datagridview -
c# - Updating records from Datagridview -
i trying update records datagrid
getting next error message:
update requires valid updatecommand when passed datarow collection modified rows
here code:
private void btnupdate_click(object sender, eventargs e) { system.data.datatable dt = ds.tables["tblimpi"]; this.impdg.bindingcontext[dt].endcurrentedit(); this.dataadapter.update(dt); messagebox.show("update successful"); }
try this:
sqldataadapter adapter; dataset ds; public void readdata() { this.ds = new dataset()) this.adapter = new sqldataadapter(query, constring)) adapter.fill(thisds, "table1"); this.ds.acceptchanges(); this.datagridview1.datasource = ds.defaultviewmanager; } public void savedata() { using (dataset changes = this.ds.getchanges()) { if (changes != null) { int updatedrows = this.dataadapter.update(changes); this.ds.acceptchanges(); } } } private void btnupdate_click(object sender, eventargs e) { savedata(); }
for understanding datagrid control
c# datagrid updatecommand
Comments
Post a Comment