How can I prevent error #1415 VB.NET Mysql?

Asked

Viewed 24 times

0

I am doing a school work of a library management, whose database is in Mysql and the DBMS I am creating is done in VB.NET, and recently I started using Foreign Keys to create relationships between tables, so I created one for the column AUT_ID table Author and linked it to the column LIV_AUT_ID from the Books table.

Inside the code I did in VB that deletes data from the Author table, I get an error while executing such command:

#1451 - Cannot delete or update a Parent Row: a Foreign key Constraint fails (paymesomething.advertisers, CONSTRAINT advertisers_ibfk_1 FOREIGN KEY (advertiser_id) REFERENCES Jobs (advertiser_id))

The code I have is this:

'Remover autor "Remover"
    '
    Private Sub Btn_remover_aut_Click(sender As Object, e As EventArgs) Handles Btn_remover_aut.Click
        If MessageBox.Show("Você tem a certeza de que quer eliminar o que selecionou?", "Atenção", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
            Dim cmd As MySqlCommand
            connection.Open()
            cmd = connection.CreateCommand()
            cmd.CommandText = "delete from Autor where AUT_ID = @cod;"
            cmd.Parameters.AddWithValue("@cod", Txt_cod.Text)
            cmd.ExecuteNonQuery()
            connection.Close()
            atualizar_aut()
        End If
    End Sub

I would like to know how I can warn the DBMS user that it is impossible to delete a Author where he is associated with Books, that is to say, how can I prevent error #1451 from appearing.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.