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 4 of 4

Thread: Catching erros

  1. #1
    JPM
    JPM is offline
    Regular Coder
    Join Date
    Mar 2004
    Location
    Norway
    Posts
    204
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Catching erros

    I have set up register form where the user enters a username, password etc. In the database I have set username as a primary key, so if someone enters a username that is already there they get this error:

    Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
    [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.

    Is there any way I can catch this error and then of course promt the user with an alert box or something?
    <JPM />

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Cincinnati, OH
    Posts
    545
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Why dont you check the db to make sure it doesnt already exist before trying to update? If not you can do a:

    Code:
    On Error Resume Next
    
    'run your update statement
    
    If err.Number <> 0 Then
    'send message to client and end processing
    End If
    You will problaly need to figure out the err number first then do the

    If err.Number=(error number when creating duplicate keys).
    does this sig match?

  • #3
    JPM
    JPM is offline
    Regular Coder
    Join Date
    Mar 2004
    Location
    Norway
    Posts
    204
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks!
    <JPM />

  • #4
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,065
    Thanks
    4
    Thanked 8 Times in 8 Posts
    If you are creating a membership system and have a memberID then you won't want that duplicated. So what I do is a simple check for .bof and .eof. If true then we know that the memberID does not exist and no error is thrown.

    Here is an example of how I do this. join.asp is the file that has the form for becoming a member. I am only showing the memberID field but all of the rest are similar. note that all fields have the value filled in
    Code:
    <tr>
       <td>Member Id</td>
       <td><input type="text" name="memberID" value="<%=sMemberId%>" ></td>
       <td><%If iError = 1 Then Response.write "This Member Id has been taken"%></td> 
    </tr>
    now in the code where you handle the form on, I would do something like this
    Code:
    Set rs.Execute("SELECT memberID FROM memberList WHERE memberID = '" & Request.Form("memberID") & "'")
    If rs.BOF or rs.EOF Then
       'the memberID has been used already 
        iError = 1
    %>
    <!--#include file="join.asp"--> 
    <%
    Else
    'go ahead and add the member
    End If


  •  

    Posting Permissions

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