Joma Rajab

Joma Rajab

  • NA
  • 110
  • 51.5k

How to delete from more than one table

Aug 16 2016 8:12 PM
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
 
 
  1. 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);  
please help
Thank you  

Answers (6)