473,327 Members | 1,919 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Howto update records with foreign key

I use VB6 with ADODB. I try to insert new records in a DB with foreign key constraints by using .AddNew
I keep getting violation messages on the foreign key

While rstSOURCERecordSet.EOF = False
rstTARGETRecordSet.AddNew
For i = 0 To rstSOURCERecordSet.Fields.Count - 1
Set fld = rstSOURCERecordSet.Fields(i)
rstTARGETRecordSet(fld.Name).Value = fld.Value
Next
rstTARGETRecordSet.Update
rstSOURCERecordSet.MoveNext
nRC = nRC + 1
'this test will commit transactions every 1000 records
If nRC = 1000 Then
cnTARGET.CommitTrans
cnTARGET.BeginTrans
nRC = 0
End If
If ProgressBar1.Value <> ProgressBar1.Max Then
ProgressBar1.Value = ProgressBar1.Value + 1
End If
ProgressBar1.Refresh
lblCurrentRecord.Caption = CStr(rstTARGETRecordSet.AbsolutePosition)
lblCurrentRecord.Refresh
DoEvents
Wend

The FK is pointing to a local Primary Key:
ALTER TABLE POINT ADD CONSTRAINT FKEY_PTSYMMETRICALPOINTID FOREIGN KEY (SYMMETRICAL_POINT) REFERENCES POINT(POINT_ID) ON UPDATE CASCADE ON DELETE SET NULL

What did I miss here? Should I use JOIN statements in my queries?
Jul 7 '11 #1
1 2035
Rabbit
12,516 Expert Mod 8TB
You haven't given us the text of the error, but I suspect the foreign key doesn't exist in the primary table.
Jul 7 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: John Pastrovick | last post by:
I use a function, myrandomPIN (), to generate random PIN numbers. The following sql query updates records with the SAME PIN number but. I want to generate DIFFERENT pin numbers for every record....
0
by: Raheel Hussain | last post by:
hi, I have a following situations, in which I want to know about how ADO.NET is supporting. SITUATION 1 ----------- I m saving a customer record on click of Save button.
2
by: Sporke13 | last post by:
I have used stored procedures to insert and select but for some reason I can not get this code to update records. Please help I must have made a dumb mistake STORED PROCEDURE CREATE Procedure...
1
by: Roderick A. Anderson | last post by:
I have two tables in two databases (Pg 7.2.1 - yes I need to upgrade but there are several other dependencies I have to resolve first) and I need to update one database's tables so they can be...
8
by: RC | last post by:
In my Access 2002 form, I have a combo box and on the AfterUpdate event I use DoCmd.RunSQL ("UPDATE .... to update records in a table. When it starts to run I get a message "You are about to...
1
by: Tom | last post by:
hello i have 2 tables linked by a common id. The first table has records with a specific field with numeric values. eg 3 or 6 or 10 etc. What i want to happen is when i create a data entry form, i...
8
by: mantrid | last post by:
Hello Im having problems working out why the following code does not work. I dont think its the sql as the error occurs on the first update which ever one is put there ($q1 or $q2). Ive swapped...
3
by: ebru | last post by:
about insert/delete/update records in mysql server with asp code how can I insert record in mysql database.. I insert into database but if I leave one text box empty, its give me error how can...
7
by: emajka21 | last post by:
I have been working on creating a HR database. Everything is working fine there but now they want a training database. I basically need a few fields from the employee table and I need the full...
7
by: ndhvu | last post by:
Tables: Buy_Header and Buy_Detail. - Buy_Header: info. of each buy (buy_id(PK, auto number), date, shop, bought_by, ...) - Buy_Detail: info. of each item from each buy (buy_detail_id(PK, auto...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.