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)
        myConnection.Open()


        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")
        Else
            MsgBox("Student With MajorName " & Trim(TextBox1.Text) & " Failure To Delete", MsgBoxStyle.OkOnly, "Info Delete Student")
        End If
        refreshComponents()
        myConnection.Close()

Recommended Answers

All 2 Replies

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.