By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,784 Members | 1,195 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,784 IT Pros & Developers. It's quick & easy.

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

P: n/a
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

Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.
"trint" <tr***********@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
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

Nov 17 '05 #2

P: n/a
David Lloyd,
If you are there, I need to ask you a question please.
Thanks,
Trint

.Net programmer
tr***********@gmail.com

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.