...

View Full Version : ASP Primary key error



zenweezil
09-27-2005, 06:51 PM
I know I have done this in the past, but can't recall how. I want to make it so my SQL insert command recognizes when it tries to insert a repeated primary key item and have it halt the insert rather than throw an asp error?

If it helps, here is my current insert command (Primary key is serial):
<%
Dim rsRMAcart

Set rsRMAcart = Server.CreateObject("ADODB.Command")
rsRMAcart.ActiveConnection = MM_conn_sql_warranty_STRING
rsRMAcart.CommandText = "INSERT INTO dbo.T_RMA_Requested (rmasession, dealerID, distID, WarrantyID, CustomerID, Serial, Item, FirstName, LastName, HomePhone, Address, City, State, Zip, Symptom, Installer, DateRemoved, Datecreated ) SELECT rmasession, dealerID, distID, WarrantyID, CustomerID, Serial, Item, FirstName, LastName, HomePhone, Address, City, State, Zip, Symptom, Installer, DateRemoved, Datecreated FROM dbo.T_RMA_Temp WHERE rmasession = '" + Replace(rsRMAcart, "'", "''") + "'"
rsRMAcart.CommandType = 1
rsRMAcart.CommandTimeout = 0
rsRMAcart.Prepared = true
rsRMAcart.Execute()

%>

OH, WAIT - do I just need to add to my WHERE parameters?

Basscyst
09-27-2005, 10:58 PM
If there is a chance that the serial could be duplicated, then it shouldn't be the primary key, you should have an auto number field set as the primary key. Then if there still shouldn't be duplicate info in the serial column, you can check if it exists prior to inserting the record. There may be another way more like what you described, but that's what I would do.

Basscyst



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum