I have a C#.NET Website that stores status logs from hardware installations. A report is stored in a report_info table and it's data entries are stored in report_data. I first insert into the report_info table and retrieve the insert ID using:
cmd.CommandText = "SELECT @@IDENTITY";
// Get the last inserted id.
aReport.reportId = Convert.ToInt32(cmd.ExecuteScalar());
aReport.reportId is then used as the Foreign Key in report_data table's entries. I have debugged to show that the reportId is correct and exists in the table, however, I get the error: "The INSERT statement conflicted with the FOREIGN KEY constraint"
Any ideas on what might cause this error would be really helpful. I'm at the 'losing patience' point ...
Thanks