473,480 Members | 2,230 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

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
2 1627
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1775
by: Tom Gao | last post by:
I have a problem. The project that I'm working on requires me to duplicate records. As in a series of records are entered into the system the user then click on a button to make these as...
3
1386
by: trint | last post by:
Three tables (all new, no data) will receive data from dBase and be transposed into them...All three have auto generated IDENTITY columns and pk and fk constraints. Can someone provide me with an...
10
6942
by: serge | last post by:
I am doing a little research on Google about this topic and I ran into this thread: ...
1
1748
by: Philippe Lang | last post by:
Hello, What is the best method to debug a database that *sometimes* gets locked in the INSERT mode? ('ps -afx | grep postgres' shows me a process that is freezed in INSERT mode.) Thanks ...
20
6061
by: John Bailo | last post by:
I have a c# program that loops through a table on a DB2 database. On each iteration it assigns data to values in the SqlParameter collection. The command text is an INSERT statement to a Sql...
8
3482
by: nano2k | last post by:
Hi Shortly, I keep invoices in a table. Occasionally, someone will fire the execution of a stored procedure (SP) that performs several UPDATEs against (potentially) all invoices OLDER than a...
7
14517
by: annecarterfredi | last post by:
I need to increase the length of CD column from char(5) to char(7) in DB2 V8.2. I am doing it this way: 1. create new_table with CD char(7) 2. do 'insert into new_table select * from...
10
8193
by: teddysnips | last post by:
SQL Server 2000 (DDL below) If I try to run this code in QA: SET IDENTITY_INSERT tblAdminUsers ON INSERT INTO tblAdminUsers (fldUserID, fldUsername, fldPassword, fldFullname,
2
45847
by: mivey4 | last post by:
Okay I have 2 tables: Table A - holds a list of new hardware serial numbers and their corresponding model (no constraints or indexes) Table B - holds a distinct list of current serial numbers...
0
7049
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6912
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7052
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7092
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6744
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4790
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4488
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3000
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
188
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.