Re: Unique Field Verification



I have the database set to reject duplications, however when the user
enters their duplicate it still treats it as if they have registered
even though the database rejects it.

I need something to send an error message to the user.



On Jan 25, 10:50 am, "tg" <tg2122...@xxxxxxxxx> wrote:
Those statements will work fine to handle an insert error with SQLserver
(and probably other DB's), no stored procedures required, and it's a single
trip to the DB, here's a few lines of code that work.

str = "insert into emaillist values( '...@xxxxxxxx' )"
on error resume next
' try the insert
Set RS = Conn.Execute ( str )

if err.number <> 0 then
response.write "oops, error on DB insert attempt"
'name exists, get user to choose a new one or DB not available
else
response.write "life is good, address added"
'success - address has been inserted
end if

"Jon Spivey" <j...@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in messagenews:%23kTX8eIQHHA.2340@xxxxxxxxxxxxxxxxxxxxxxx

you can also set the field as unique in the db then try the insert, if
there's an error ask the user to chose a new name, eg
on error resume next
' try the insert
if err.number <> 0 then
' name exists, get user to chose a new one
else
' success - name doesn't exist
end if
on error goto 0

The advantage is that you're only hitting the database once rather than
twice. Obviously this only applies to access, in sql server you'd use a
stored procedure to do the insert and return success or failure as an
output param.

Cheers,
Jon

"Stefan B Rusynko" <sbr_en...@xxxxxxxxxxx> wrote in message
news:u$9AqCGQHHA.1248@xxxxxxxxxxxxxxxxxxxxxxx
The way to check is to query the DB for that new user name and that email
address before you write the new ones to the DB
If you get a EOF the new ones were not a dupe
If you get a hit the new ones are dupes

_____________________________________________
SBR @ ENJOY (-: [ Microsoft MVP - FrontPage ]
"Warning - Using the F1 Key will not break anything!" (-;
_____________________________________________

"frontpagecustoms.com" <m...@xxxxxxxx> wrote in message
news:1169695966.446238.105510@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
| Does anyone have a script or code that will verify a user name or email
| address is unique in a database entry form?
|

.



Relevant Pages

  • Re: Import Data succeeds but doesnt copy data?
    ... Looks like you are copying from a database to the SAME ... I mentioned that I copied to a new dB on the destination server ... Configure the TransferProvider with files and Source/Destination ...
    (microsoft.public.sqlserver.tools)
  • Re: Update sendmails email result to database
    ... Use logwatch to monitor mail log, update database according to ... Cheow Yong ... success status in database. ... find out any problem happened after email send to sendmail server. ...
    (comp.mail.sendmail)
  • Re: Update sendmails email result to database
    ... success status in database. ... find out any problem happened after email send to sendmail server. ... I think that we can write a milter program like following: ...
    (comp.mail.sendmail)
  • Re: DBConcurrencyException on dataset update (because of datetime primary key ?)
    ... I fill a Dataset with data extracted from a table of my database, ... Date/Time field. ... I also tested to fix the OleDbType of parameters, without success. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Selling MV...
    ... I am pleased that you received such a positive response. ... your success and am sure the information you provide is valuable to large IT ... longer care, if they ever did, about the database. ...
    (comp.databases.pick)