Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
//Delete Record : Disconnected

public void DeleteBook(int BookId)
    {
      1)  DataRow dr1 = ds.Tables["tbl_Books"].NewRow();
      2) dr1 = ds.Tables["tbl_Books"].Rows.Find(BookId);
      3)  dr1.Delete();       
      4)  SqlCommand delcmd = new SqlCommand("Delete from tbl_Books where BookId="  BookId.ToString(), cn);
      5)  SqlCommandBuilder cmdb = new SqlCommandBuilder(da1);
      6)  da.DeleteCommand = delcmd;
      7)  da.Update(ds.Tables ["tbl_Books"]);
    
    }


The Above code is working fine. But the concept is not clear.
After Execution of Statement No.(3) the particular row is romoved from the DataSet.
Then the Update Commad (ie Statement(7)) should update the data to database.

Then what is the use of Statement (4),(5) and (6).
Is there any other way to write above code without "Delete Query"
If so please prove the code....
Posted
Updated 17-Mar-11 2:51am
v2

1 solution

//I Got the answer .. What i am expecting was as follows..
//=========================================================
public void DeleteBook(int BookId)
{
DataRow dr1 = ds.Tables["tbl_Books"].NewRow();
dr1 = ds.Tables["tbl_Books"].Rows.Find(BookId);
dr1.Delete();
SqlCommandBuilder cmdb = new SqlCommandBuilder(da);
da.Update(ds.Tables ["tbl_Books"]);
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900