c# - Null DataSet when using SqlDataAdapter.Update method -


i'm attempting update values in database editing them in datagridview (windows form). however, when calling sqldataadapter.update() in code below, it's saying dataset null. i've searched online , found adding acceptchanges() after getchanges() has worked people, has not fixed error.

below code trying use, appreciated.

private void datagridview1_cellendedit(object sender, datagridviewcelleventargs e)     {         carhiredatasetbindingsource.endedit();          string connectionstring = "data source=sqlserver;initial catalog=carhire;integrated security=true";         string selectcommand = "select * carhire.dbo.customer";          sqlconnection con = new sqlconnection(connectionstring);         con.open();          dataset ds = carhiredataset.getchanges();         carhiredataset.acceptchanges();         dataadapter da = new sqldataadapter(selectcommand, connectionstring);         da.update(ds);          con.close();     } 

edit: tried this, still same error.

private void datagridview1_cellendedit(object sender, datagridviewcelleventargs e)     {         carhiredatasetbindingsource.endedit();          string connectionstring = "data source=sqlserver;initial catalog=carhire;integrated security=true";         string selectcommand = "select * carhire.dbo.customer";          sqlconnection con = new sqlconnection(connectionstring);         con.open();          datatable dt = carhiredataset.tables["customer"].getchanges();         dataset ds = new dataset();         ds.tables.add(dt);         ds.acceptchanges();         dataadapter da = new sqldataadapter(selectcommand, connectionstring);         da.update(ds);          con.close();     } 

i think better execute update when user finishes editing row.

move code cellendedit event rowvalidated event.

private void datagridview1_rowvalidated(object sender, datagridviewcelleventargs e) {     //here place code update } 

Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -