Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jan 2003
    Posts
    111
    Thanks
    2
    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):
    <%
    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?
    Last edited by zenweezil; 09-27-2005 at 05:53 PM.

  • #2
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    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.

    Basscyst
    Helping to build a bigger box. - Adam Matthews


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •