Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
Thread: ASP Primary key error
09-27-2005, 06:51 PM #1
- Join Date
- Jan 2003
- Thanked 0 Times in 0 Posts
ASP Primary key error
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):
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
OH, WAIT - do I just need to add to my WHERE parameters?
Last edited by zenweezil; 09-27-2005 at 06:53 PM.
09-27-2005, 10:58 PM #2
- Join Date
- Jul 2003
- CA, USA
- Thanked 20 Times in 20 Posts
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.
Helping to build a bigger box. - Adam Matthews