c# - Unable to delete,update in gridview using -


every time run program , click on delete button in gridview exception

object reference not set instance of object

and point " here's code, i'm using these 2 methods in button, data fetched can't delete or update in gridview.

private void getdatafromdb() {     string cs = configurationmanager.connectionstrings["dbcs"].connectionstring;     sqlconnection con = new sqlconnection(cs);      string str = "select * person";     sqldataadapter da = new sqldataadapter(str, con);     dataset ds = new dataset();      da.fill(ds, "person");     ds.tables["person"].primarykey = new datacolumn[] { ds.tables["person"].columns["id"] };      cache.insert("dataset", ds, null, datetime.now.addminutes(50), system.web.caching.cache.noslidingexpiration);      gridview1.datasource = ds;     gridview1.databind();     lblmsg.text = "data loaded database"; }  private void getdatafromcache() {     if (cache["dataset"] != null)     {         dataset ds = (dataset)cache["dataset"];         gridview1.datasource = ds;         gridview1.databind();     } }  protected void gridview1_rowdeleting(object sender, gridviewdeleteeventargs e) {     if (cache["dataset"] != null)     {         dataset ds = (dataset)cache["dataset"];         datarow dr = (datarow)ds.tables["person"].rows.find(e.keys["id"]);          dr.delete();   // <- here throws exception          cache.insert("dataset", ds, null, datetime.now.addhours(24), system.web.caching.cache.noslidingexpiration);          getdatafromcache();     } } 


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -