4 Replies - 4440 Views - Last Post: 08 February 2013 - 04:04 PM Rate Topic: -----

#1 gege  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 07-April 09

Asp.net delete data from dataset and database in disconnected mode

Posted 08 February 2013 - 02:14 PM

 protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string ph = ds.Tables[0].Rows[e.RowIndex][0].ToString();
        adpt = new SqlDataAdapter();
        comm = new SqlCommand();
        comm.CommandText = "delete from Categories where CategoryID = " + ph;
        comm.CommandType = CommandType.Text;
        comm.Connection = con;
       
        adpt.DeleteCommand = comm;
       
        adpt.Update(ds);

        select();

        GridView1.DataSource = ds;
        GridView1.EditIndex = -1;
        GridView1.DataBind();
    }



this code is supposed to delete a record in dataset and then delete it from database using the gridview, it doesn't generate any errors but it doesn't delete the record from the dataset

Is This A Good Question/Topic? 0
  • +

Replies To: Asp.net delete data from dataset and database in disconnected mode

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9568
  • View blog
  • Posts: 36,222
  • Joined: 12-June 08

Re: Asp.net delete data from dataset and database in disconnected mode

Posted 08 February 2013 - 02:21 PM

12	       adpt.Update(ds);


Why are you calling update and not delete?
Was This Post Helpful? 0
  • +
  • -

#3 gege  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 07-April 09

Re: Asp.net delete data from dataset and database in disconnected mode

Posted 08 February 2013 - 02:35 PM

There is no delete method in data adapter update is used for insert, update and delete it means any update operation not the update command specific

This post has been edited by gege: 08 February 2013 - 02:36 PM

Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9568
  • View blog
  • Posts: 36,222
  • Joined: 12-June 08

Re: Asp.net delete data from dataset and database in disconnected mode

Posted 08 February 2013 - 02:39 PM

ah.. that's right. Okay.. now check your dataset's row. Is the row state marked as 'deleted'? If not then the adapter won't filter it to the 'delete' option.

Of course you could just cut out of the chase of the adapter and just do an 'execute non query' on your command object.
Was This Post Helpful? 1
  • +
  • -

#5 gege  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 07-April 09

Re: Asp.net delete data from dataset and database in disconnected mode

Posted 08 February 2013 - 04:04 PM

Thank you, I knew the error, I was missing this line
ds.Tables[0].Rows[e.RowIndex].Delete();

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1