StudentDetails.Students
是與RegistrationDetails.Registration
形成關係的主表。因此,StudentID
是前者的主鍵,而後者是外鍵。如何從兩個表中刪除相關記錄的內容?
現在我嘗試以下每個碼但每個前兩個給出錯誤信息「附近有語法錯誤‘A’」,並在中的第三個DbTransaction
的情況一樣「DIM反式作爲DbTransaction」是也不是有效的類型。請使用SQL Server 2008專業版。
1.
cmd = New SqlCommand("DELETE FROM StudentDetails.Students a, RegistrationDetails.Registration b WHERE (b.StudentId=a.StudentId) AND a.StudentId='" & txtStudentID.Text & "'", cn)
2.
cmd = New SqlCommand("DELETE FROM StudentDetails.Students a, RegistrationDetails.Registration b WHERE (b.StudentId=a.StudentId) AND a.StudentId='/" & txtStudentID.Text & "/'", cn)
您是否試圖根據學生ID從每個表中刪除一行? – Chris
是的,我試圖從主表上刪除基於StudentID的記錄。 – Akaglo
儘管在這種情況下可能並不重要,但是請記住,當您使用'「&txtStudentID.Text&」'代替SQL參數時,您打開了自己的SQL注入功能 – Seph