Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem adding new record to database via ASP

Status
Not open for further replies.

david7777777777

Programmer
Sep 26, 2001
417
US
I'm adding new records to a SQL 2000 database via ASP pages. I'm slightly re-designing an app I made to track shipments of boxes. The old app was working fine using the initialize then add routine. However, with this new version of teh application, I'm not using an auto-created integer field as the Primary Key in the tbl_Shipments table. Instead I'm using the tracking number as the Primary Key field for the tbl_Shipments table. I'm thinking this is where I'm having a problem.

My old method of initializing a new, blank record with a btn_NewShipment button, having the user fill-in the DTC's with the data, then saving the new record with a btn_Save button, generates errors. I've included my latest error below. If you need more info to know what's going on let me know. It's a fairly simple and straight-forward form and process. Thanks.


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

[Microsoft][ODBC SQL Server Driver][SQL Server]Violation of PRIMARY KEY constraint 'PK_tbl_Shipments'. Cannot insert duplicate key in object 'tbl_Shipments'.

/_ScriptLibrary/Recordset.ASP, line 311


This error appears after I've filled in the DTC's and clicked the btn_Save button to save the new record.
 
I found the problem. I had experienced some sort of ADO or ODBC error while I was editing my page one day, but it happened while I was trying to figure out something else so I paid little, too little, attention to it.

When I dragged another DTC onto my already built page, VI asked me if I wanted to activate the Scripting Object Model for this page. I though that was strange since I usually only get that prompt when I'm adding the FIRST DTC to the page. Oh well, should have paid more attention to that little quirk, because it threw duplicate code onto my page and cause all sorts of error. HEre's the code that was duplicated on my ASP page:

<% ' VI 6.0 Scripting Object Model Enabled %>
<!--#include file=&quot;_ScriptLibrary/pm.asp&quot;-->
<% if StartPageProcessing() Then Response.End() %>
<FORM name=thisForm METHOD=post>

and this code was duplicated at the end of the page....

<% ' VI 6.0 Scripting Object Model Enabled %>
<% EndPageProcessing() %>
</FORM>

I deleted this extra code and all problems disappeared.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top