Reputation: 89
I have a gridview in my web project and I connect it with the SqlDataSource. The select command contain fields from 3 table, and I created commandField for gridview so that users can delete their Purchase Items. here is my C# select code:
SqlDataSource1.SelectCommand =
"SELECT Production.Name, Production.Price ,PurchaseItem.Quantity,
Production.Info ,Purchase.OrderDate
FROM Production
INNER JOIN PurchaseItem on (Production.ID = PurchaseItem.ProductID)
INNER JOIN Purchase on(Purchase.ID = PurchaseItem.PurchaseID)
WHERE Purchase.UserID = '" + Convert.ToInt64(da.getuserid(Session["Mysys"].ToString()).FirstOrDefault()) + "'";
GridView1.DataSourceID = SqlDataSource1.ID;
GridView1.DataBind();
My problem is the DeleteCommand of the SqlDataSource. is it Possible to do such thing?
Upvotes: 0
Views: 235
Reputation: 145
Production, PurchaseItem, Purchase are the tables you want to delete the items by selecting on your gridview right? if so.
you just have to make a delete query like
DELETE FROM PRODUCTION WHERE ID = VALUE
DELETE FROM PURCHASEITEM WHERE ID = VALUE
DELETE FROM PURCHASE WHERE ID = VALUE
and if you want to delete running a single query only you may try INNER JOIN:
DELETE table1, table2 FROM table1 INNER JOIN table2
WHERE table1.id=table2.id and table1.id = 'VALUE'
Upvotes: 2