![]() |
| ||
| The INSERT statement conflicted with the FOREIGN KEY constraint Hey All, I am using MSSQL -2005 with VB6. I have created a master table tblCompany and detail Table tblDetail having foreign key relationship. When i try to insert a value within a TRANSACTION I am getting Error No. -2147217873 at Line No. 0 (The INSERT statement conflicted with the FOREIGN KEY constraint "FK_tblDetail_tblCompany". The conflict occurred in database "DBTest", table "dbo.tblCompany", column RefID.) . please help me to solve this problem. CREATE TABLE [dbo].[tblCompany]( CODE : Dim intID as Integer |
| ||
| Re: The INSERT statement conflicted with the FOREIGN KEY constraint Please wrap your posts in [code] tags in the future. Can you post the raw SQL you're using here? I created your tables and was able to insert OK. Insert Into tblCompany (CompanyName, Amount) Values ('Sample', 2500) |
| ||
| Re: The INSERT statement conflicted with the FOREIGN KEY constraint Hey sknake, Thanks for your Reply, I Found that the adoMaster!RefID is returning the value not from the specified table but it is returning then max of IDENTITY Value from the Database. For Example Table Name: tblCompany has Primary(identity) Column RefID with last Value of 10 Table Name: tblDetail has Primary(identity) Column DetailID with Last Value 20 Table Name: tblValue has primary(identity) Column ValueID with Last Value 50 After Updating tblCompany with a new record adoMaster!RefID is returning Value 51 which is the next identity Value of tblValue Table instead of returning 11 Which is the next identity Value of tblCompany. I found this when i Inserted SQL statement after adomaster.update SQL Statement Inserted : adoID.Open "Select Max(RefID) from tblCompany", adoConn, adOpenForwardOnly, adLockReadOnly Here adoID(0).Value is returning 11 that has to be return by adomaster!RefID after Updating with new record. Please guide me |
| All times are GMT -4. The time now is 3:24 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC