View Full Version : How to search duplicate values in db
paulafernandes
12-05-2002, 12:13 PM
Hello!
I want to search duplicate values in my database. The field that I want to search is a primary key.
I'm doing a SQL Insert string and the user can't put a number that is already in the database.
Paula
Roelf
12-05-2002, 12:20 PM
if the field is defined as a primary key, the db takes care of that itself
paulafernandes
12-05-2002, 12:24 PM
Yes, I know. But I want to give the user a message so he knows that the value is a duplicated value...
Roelf
12-05-2002, 12:34 PM
try something like:
strUserEnteredValue = Request.Form("fieldname")
strSql = "SELECT fieldname FROM tablename WHERE fieldname = '" & strUserEnteredValue & "'"
objRecordSetObject.Open strSql
If objRecordSetObject.EOF Then
' the value was found
' do your message thingy
Else
' value doesn't exist
' do your update thingy
End If
paulafernandes
12-05-2002, 02:46 PM
Thank's!!! It worked just fine!
Except for one thing:
If objRecordSetObject.EOF Then
' the value was found
' do your message thingy
Else
' value doesn't exist
' do your update thingy
End If
It should be:
If objRecordSetObject.EOF Then
' the value was *not* found
Else
' the value was found
End If
Thank's for the help!
Paula
Roelf
12-05-2002, 04:12 PM
oops, you're right :o
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.