Reputation: 85
I need help about this issue. There is a problem but I could not find it
error message is
Cannot add or update a child row: a foreign key constraint fails (
db_kiosk
.tbl_oyunhareketi
, CONSTRAINTOH_KioskID
FOREIGN KEY (OH_KioskID
) REFERENCEStbl_kiosk
(Kiosk_ID
) ON DELETE NO ACTION ON UPDATE NO ACTION)
Here is my code c#
string sql = "insert into db_kiosk.tbl_oyunhareketi (OH_OyuncuID,OH_KioskID,OH_Puan,OH_Tarih,OH_ControlRow) values ('"+Convert.ToInt32(Label4.Text)+"','"+Convert.ToInt32(Label3.Text)+"','" + Puan_txt.Text + "' , '" + Tarih_txt.Text + "',1)";
Label3.Text = Kiosk_Drop.SelectedValue;
Label4.Text = Oyuncu_Drop.SelectedValue;
Kiosk_Drop
and Oyuncu_Drop
are the dropdownlist in ASP.net and they are in the selectedIndexChanged
function. When I display the labels the values are coming properly but problem is insertion. DB attributes also integer
but I couldn't find the problem.
Upvotes: 1
Views: 51
Reputation: 12818
You have foreign key constraint that prevents you from adding rows to the child table before you have relevant information in the parent table.
In this case you should first populate tbl_kiosk
before adding a row to tbl_oyunhareketi
. Rows are matched by columns OH_KioskID
and Kiosk_ID
.
Upvotes: 1