...

View Full Version : Catching erros



JPM
07-29-2004, 02:21 PM
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?

allida77
07-29-2004, 02:27 PM
Why dont you check the db to make sure it doesnt already exist before trying to update? If not you can do a:



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).

JPM
07-29-2004, 02:45 PM
Thanks!

miranda
08-03-2004, 06:49 PM
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


<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


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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum