if (dt!= null && dt.Rows.Count > 0) { // gets the corresponding row from accountTable if (dt.Tables[0] != null && dt.Tables[0].Rows.Count > 0) { dr = dt.Tables[0].Rows.Find(value); if (dr!= null) { // removes the row if row exists dt.Tables[0].Rows.Remove(dr); } } // merges the datatable ds.Merge(dt); }