Detecting Duplicates in Database Column

Results 1 to 4 of 4

Thread: Detecting Duplicates in Database Column

  1. #1
    KTULKevin Guest

    Default Detecting Duplicates in Database Column

    I&#039;m trying to create a username/password login that will not allow duplicate usernames. I know how to create the database, but I need to create a script that would detect duplicates and create a statement that would tell them the username already exists. I&#039;m not sure even where to start on detecting duplicates...please advise.<BR>Thanks<BR>

  2. #2 Guest

    Default RE: Detecting Duplicates in Database Column

    say you have the fields [User] and [Pass] and corresponding form fields :<BR>&#060;form action="x.asp" method=post&#062;<BR>&#060;input type=text name=User&#062;<BR>&#060;input type=password name=pass&#062;<BR>&#060;input typ=submit&#062;<BR>&#060;/form&#062;<BR><BR>In x.asp you have:<BR><BR>Qry = "Select * from Users where User = &#039;" & Request.Form("User") & "&#039;"<BR>set rs=Conn.execute(Qry)<BR>If rs.eof and rs.bof then<BR>&#039; The user does not exist so you can insert the new one<BR>else<BR>&#039; Username already exists, so show error message!<BR>End If

  3. #3
    KTULKevin Guest

    Default RE: Detecting Duplicates in Database Column

    Okay, did that and now I&#039;m getting the following error:<BR><BR>Microsoft VBScript runtime error &#039;800a01a8&#039; <BR><BR>Object required: &#039;&#039; <BR><BR>/sports/draft/userexists.asp, line 27 <BR><BR>Here&#039;s the script<BR><BR> Dim dcnDB &#039; As ADODB.Connection<BR> Dim strDatabaseLocation &#039; As String<BR> Dim CmdAddRecord<BR> Dim rsNews &#039; As ADODB.Recordset<BR> Dim strSQL &#039; As String<BR> <BR> strDatabaseLocation = "D:draft.mdb"<BR> Set dcnDB = Server.CreateObject("ADODB.Connection")<BR> dcnDB.ConnectionString = _<BR> "Provider=Microsoft.Jet.OLEDB.4.0;" _<BR> & "Persist Security Info=False;Data Source=" _<BR> & strDatabaseLocation<BR> dcnDB.Open<BR> <BR> strSQL = "SELECT * FROM entrants " _<BR> & "WHERE Username = " _<BR> & "&#039;" _<BR> & Request("Username") _<BR> & "&#039;"<BR> Set rsNews = dcnDB.Execute(strSQL)<BR><BR>IF rsNews.EOF AND rsNews.BOF THEN<BR><BR>CmdAddRecord.Open strSQL, dcnDB, 1, 3<BR>CmdAddRecord.AddNew<BR>CmdAddRecord.Fields("N ame") = Request("Name")<BR>CmdAddRecord.Fields("Phone") = Request("Phone")<BR>CmdAddRecord.Fields("Username" ) = Request("Username")<BR>CmdAddRecord.Fields("Passwo rd") = Request("Password")<BR>CmdAddRecord.Update<BR>CmdA ddRecord.Close<BR>Set CmdAddRecord = Nothing<BR>dcnDB.Close<BR>Set dcnDB = Nothing<BR>Response.Redirect "/sports/draft/pick1.asp?name=" _<BR>& "&#039;" _<BR>& Request("Name") _<BR>& "&#039;" _<BR>& "&phone=" _<BR>& "&#039;" _<BR>& Request("Phone") _<BR>& "&#039;" _<BR>& "&username=" _<BR>& "&#039;" _<BR>& Request("Username") _<BR>& "&#039;" _<BR>& "&password=" _<BR>& "&#039;" _<BR>& Request("Password") _<BR>& "&#039;"<BR><BR>ELSE<BR>Response.Write "The username you have requested has already been taken. Please go back and try another one."<BR>END IF<BR><BR>Any ideas?<BR>Thanks<BR>

  4. #4
    Join Date
    Dec 1969

    Default Object not created

    In your code, you are using CmdAddRecord as if it were an object whereas it has not been created.<BR>Besides, using a record set for adding data is a bad habit. The INSERT statement in SQL is a better way.

Posting Permissions

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