I need to delete from multiple tables which are linked to each other and the delete is based on a selected value from a drop-down list and this drop-down list contains id of the first table
the query below works fine for deleting from Material table where there is no row for that material id in other tables. However, when id is in other tables I could not delete
- SqlCommand cmd = new SqlCommand("Delete From dbo.Material Where MaId='" + DropDownList5.SelectedItem.Value.ToString() + "'; Delete from Quiz where MaID = '" + DropDownList5.DataValueField + "';Delete from Lastviewed where MaID = '" + DropDownList5.DataValueField + "'; Delete from Comments where MaID = '" + DropDownList5.DataValueField + "'; ", conn);
Thank you

Tapan PatelRank #614 · 3.9K reputationPosted Aug 16, 2016, 5:26 PM EDT
http://stackoverflow.com/questions/6260688/how-do-i-use-cascade-delete-with-sql-server
Joma Rajab125 reputationPosted Aug 17, 2016, 1:16 AM EDT
Tapan PatelRank #614 · 3.9K reputationPosted Aug 17, 2016, 4:53 AM EDT
Midhun TpRank #388 · 6.5K reputationPosted Aug 17, 2016, 6:46 AM EDT
Bikesh SrivastavaRank #108 · 20.3K reputationPosted Aug 17, 2016, 5:19 AM EDT
Pratik ShirseRank #3,199 · 449 reputationPosted Sep 10, 2016, 2:48 AM EDT