The following example simply illustrate how you can delete rows using dataset and command builder in C#. As a C# programmer you may know how important a dataset is.
Here in our example, we first create a database adapter pointing to some table rows and then build a dataset which is the local representation of database table.
Common.StockPurchase_Part = new SqlDataAdapter("select * from purchasepart where billno=" + bno, Common.con); Common.StockPurchasePartDataset = new DataSet(); Common.StockPurchase_Part.Fill(Common.StockPurchasePartDataset);
Now lets create a command builder and configure the delete command of the adapter.
Common.cmdbuilder = new System.Data.SqlClient.SqlCommandBuilder(Common.StockPurchase_Part); Common.StockPurchase_Part.DeleteCommand = Common.cmdbuilder.GetDeleteCommand();
Now we need to mark the rows we want to delete, using the Rows collection. In my example , I have only one rows, which is stored in the 0th position. So my code will look like
Now all I need is just call the Update method of the adapter and it simply works.
Hope you got the technique.