I used this code delete recods from table ............
in VBP is database name
Sell-is a table name
The DELETE statement conflicted with the REFERENCE constraint "FK_Sells_Product_Details". The conflict occurred in database "VBP", table "dbo.Sells", column 'P_Id'. The statement has been terminated.

Dim check As Integer

        Dim cmdproduct As New SqlCommand
        Dim daStudent As New SqlDataAdapter
        Dim dsStudent As New DataSet
        myConnection = New SqlConnection(connectionstring)

        cmdproduct = myConnection.CreateCommand
        cmdproduct.CommandText = "DELETE FROM Product_Details WHERE P_Id ='" & Trim(ComboBox2.Text) & "'"
        check = cmdproduct.ExecuteReader.RecordsAffected
        If check > 0 Then
            MsgBox("Student With MajorName " & Trim(TextBox1.Text) & " Succesfully To Delete", MsgBoxStyle.OkOnly, "Info Delete Student")
            MsgBox("Student With MajorName " & Trim(TextBox1.Text) & " Failure To Delete", MsgBoxStyle.OkOnly, "Info Delete Student")
        End If

You have another table which uses that primary key as a foreign key. If you delete that record then the other table will have an orphan (a record that doesn't point back anywhere). If you are using MS SQL you should be able to set up something called cascading referential integrity. This causes all dependent records in other tables to be automatically deleted when the primary record is deleted. I've never used it but you can read up on it here.

how to write queries in sql 2005...................
Reverend Jim

Edited 4 Years Ago by Dili1234

This question has already been answered. Start a new discussion instead.