Greetings,
I have a problem with visual studio, I'm trying to insert values into a table with a foreing key, but I keep getting this error
The INSERT statement conflicted with the FOREIGN KEY constraint"FK__sales__id_book_1920BFC". THe conflict ocurred in database "....Bookstore.mdf", table"dbo.INVENTARY", colum 'id_book'.
The statement has been terminated.
I've searched for about 2 hours now and all the answers I found said the same "you need to have the table with the Key that the FK is trying to access to" and "you need to have at least 1 record in the parent table which has the key colum".
I do have them, and even so I'm getting that error.
Here's my code:
Public Sub AddMember(id_book As Integer, member As Boolean, id_member As Integer, date_sale As Date, time_sale As Date)
Try
Dim strInsert As String = "INSERT INTO SALES (id_book,member,id_member,date_sale,time_sale) Values " & _
"(@id_book,@member,@id_member,@date_sale,@time_sale)"
SQLCon.Open()
SQLCmd = New SqlCommand(strInsert, SQLCon)
SQLCmd.Parameters.AddWithValue("id_book", id_book)
SQLCmd.Parameters.AddWithValue("member", member)
SQLCmd.Parameters.AddWithValue("id_member", id_member)
SQLCmd.Parameters.AddWithValue("date_sale", date_sale)
SQLCmd.Parameters.AddWithValue("time_sale", time_sale)
SQLCmd.ExecuteNonQuery()
SQLCon.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Any other ideas?