Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDNN Open Source...DNN Open Source...Module ForumsModule ForumsGalleryGalleryThe INSERT statement conflicted with the FOREIGN KEY constraintThe INSERT statement conflicted with the FOREIGN KEY constraint
Previous
 
Next
New Post
7/3/2009 6:19 AM
 

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](

    [RefID] [int] IDENTITY(1,1) NOT NULL,

    [CompanyName] [varchar](250) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,

    [Amount] [decimal](18, 2) NOT NULL CONSTRAINT [DF_tblCompany_Amount]  DEFAULT ((0)),

 CONSTRAINT [PK_tblCompany_1] PRIMARY KEY CLUSTERED

(

    [RefID] ASC

)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]

) ON [PRIMARY]

 

CREATE TABLE [dbo].[tblDetail](

    [DetailID] [int] IDENTITY(1,1) NOT NULL,

    [RefID] [int] NULL,

    [Amount] [decimal](18, 2) NOT NULL CONSTRAINT [DF_tblDetail_Amount]  DEFAULT ((0)),

 CONSTRAINT [PK_tblDetail] PRIMARY KEY CLUSTERED

(

    [DetailID] ASC

)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]

) ON [PRIMARY]

 

GO

ALTER TABLE [dbo].[tblDetail]  WITH CHECK ADD  CONSTRAINT [FK_tblDetail_tblCompany] FOREIGN KEY([RefID])

REFERENCES [dbo].[tblCompany] ([RefID])

ON UPDATE CASCADE

ON DELETE CASCADE

GO

ALTER TABLE [dbo].[tblDetail] CHECK CONSTRAINT [FK_tblDetail_tblCompany]

 

 

 

CODE :

 

Dim intID as Integer

 

adoconn.BeginTrans

with adoRsMaster

    .Open "Select * from tblCompany Where 1=2",adoconn,adOpenDynamic,adLockOptimistic  

    addnew

    !CompanyName="Sample"

    !Amount =2500

    .update

intID = !RefID

end with

with adorsDetail

    .Open "Select * from tblDetail Where 1=2",adoconn,adOpenDynamic,adLockOptimistic  

    .addnew

    !RefID = intID

    !Amount = 2500

    .update

end with

adoconn.commitTrans

 

 

 

 

 
New Post
7/3/2009 7:42 AM
 

This does not seem DNN related & Its been far to many years(8+) since I did classic ADO or VB6. Are you sure intID actually contains the right ID?

 
Previous
 
Next
HomeHomeDNN Open Source...DNN Open Source...Module ForumsModule ForumsGalleryGalleryThe INSERT statement conflicted with the FOREIGN KEY constraintThe INSERT statement conflicted with the FOREIGN KEY constraint


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out