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
qry="Select batchreturndetailid from batchreturndetail where countryid=" & strcountryid
rsbatchreturndetail.Open qry, oDBConn,3,3
if rsbatchreturndetail.eof then
strbatchreturndetailid = 1
qry1="Select max(batchreturndetailid) as batchreturndetailidmax from batchreturndetail where countryid=" & strcountryid
if qry1<>"" then
rsbatchreturndetailmax.Open qry1, oDBConn,3,3
if not rsbatchreturndetailmax.eof then
'response.write "strbatchreturndetailid" & strbatchreturndetailid
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() & "#)"
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