Solved

Creation of duplicate values in the index, primarykey or relationship using ASP

Posted on 2006-07-13
1
268 Views
Last Modified: 2006-11-18
Hi,

  I am working with ASP on Access Database and tried inserting a new record into the database but encountered the following error:

Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC Microsoft Access Driver] The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries and try again.

/admin/sys/table_change/joborder/jobatchdetail_new_ins.asp, line 79


I displayed the query for inserting into the table and I could see nothing wrong in the query.
Basically, I have a batchreturndetails table with batchreturndetailsid as the primary key. Before I insert a new record into the table, I retrieved the latest batchreturndetailsid, add 1 to it and include it in the insert statement. I could insert the first record. But it gives me the above problem for subsequent records.

The ASP code looks like this:

'Check for first record of repairdetail by country else find max value
Set rsbatchreturndetail=server.CreateObject("ADODB.Recordset")

qry="Select batchreturndetailid from batchreturndetail where countryid=" & strcountryid

rsbatchreturndetail.Open qry, oDBConn,3,3

if rsbatchreturndetail.eof then
    strbatchreturndetailid = 1
else
    qry1="Select max(batchreturndetailid) as batchreturndetailidmax from batchreturndetail where countryid=" & strcountryid
    'response.write qry1
end if

rsbatchreturndetail.close
set rsbatchreturndetail=nothing

if qry1<>"" then
    Set rsbatchreturndetailmax=server.CreateObject("ADODB.Recordset")
    rsbatchreturndetailmax.Open qry1, oDBConn,3,3
    if not rsbatchreturndetailmax.eof then
       strbatchreturndetailid=trim(rsbatchreturndetailmax("batchreturndetailidmax"))+1
    end if
    rsbatchreturndetailmax.close
    set rsbatchreturndetailmax=nothing
end if
'response.write "strbatchreturndetailid" & strbatchreturndetailid
'response.end

sqlcmd="Insert into batchreturndetail (batchreturndetailid,repairid,indexno,returndate,qty,abletorepairflag,unabletorepairflag,deleteflag,memberid,countryid,regdate)" & _
"values (" & strbatchreturndetailid & "," & strrepairid & "," & strindexno & ",#" & strreturndate & "#," & strqty & "," & strabletorepair & "," & _
strunabletorepair & ",0," & strmemberid & "," & strcountryid & ",#" & Now() & "#)"

'response.write sqlcmd
'response.end

oDBConn.Execute sqlcmd

My code works fine initally on my local PC but when I migrated to a remote server, it gave me the above errror.
Don't think it is the cursor error cos I use the same cursor for other parts of the code as well and it is working fine.

Many thanks for your advice
 
0
Comment
Question by:thaishin
1 Comment
 
LVL 77

Accepted Solution

by:
peter57r earned 500 total points
ID: 17098452
Hi thaishin,
You are asking for the max id of records for a given country.
That says nothing about what records exist for other countries whose ids could be higher than the country you have asked for.

You need to get the max of all records irrespective of country.


Pete
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Server configuration for MS Access - SQL Server app 8 69
hit enter key to run macro 13 23
Ms Access VBA Variables 6 26
deduplicating based on criteria 2 21
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question