How can I use INSERT w/Constraints in other tables (c#)?...

  • Thread starter Thread starter trint
  • Start date Start date
T

trint

I am trying to insert a record, but I have to get an automatically
created identity field at the same time to do this.

string strSQL2 = "INSERT INTO tblTravelDetail(MemberID, " +
" TravelEventID, " +
" CreatedDateTime, " +
" Operator) " +
"VALUES ('" + TxtMLV.Text.Trim() + "', " +
" '" + TxtEventID+ "', " +
" '" + TxtDATE.Text.Trim() + "', " +
" '" + "operator name" + "') " +
"SELECT @@IDENTITY AS TravelDetailID" ;

This code doesn't work because it causes this error:
An unhandled exception of type
'System.Runtime.InteropServices.COMException' occurred in db2sql.exe

Additional information: INSERT statement conflicted with COLUMN FOREIGN
KEY constraint 'FK_tblTravelDetail_tblTravelEvent'. The conflict
occurred in database 'tsNess', table 'tblTravelEvent', column
'TravelEventId'.

What will I have to do to do get a handle on this? I have been doing
INSERT for two years with vb.net and c#, but this has me puzzled what
to do next.
Thanks,
Trint
 
Trint:

It appears, although I cannot be certain, that your Insert statement may be
violating a foreign key constraint. In other words, you may be trying to
insert a TravelEventID that does not exist in the TravelEvent table.

It would be helpful to know more about the schema of the two tables and the
constraints.

--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.
 
David Lloyd,
If you are there, I need to ask you a question please.
Thanks,
Trint

.Net programmer
(e-mail address removed)
 
Back
Top