This topic is locked

Duplicate

5/12/2010 11:16:53 PM
ASPRunnerPro General questions
A
alexandrelss author

Gentlemen,
I have the table below.

-----------------------------

id (auto)

product (text)

---------------------------------

How not to duplicate names in the field product? I tried and failed events. Can anyone help me?
( )s

J
Jane 5/13/2010

Hi,
use Before record added/Before record updated events on the Eventstab to check entered values and show error message for duplicated records.

Check sample Check if specific record exists action.

A
alexandrelss author 5/17/2010

See this example below, I made only on page ADD. not want to define, because the inclusion is dynamic
--------------------------------------------------------------------------------
'** Display a message on the Web page ****

Response.Write "[color="#FF0000"]Duplicate record"
'** Check if specific record exists ****

dim rsExists

set dal_table=dal.Table("")

set rsExists = dal_table.Query("[color="#FF0000"]produtc='Notebook'","")

if not rsExists.eof then

' if record exists do something
else

' if dont exist do something else
end if

rsExists.Close : set rsExists = Nothing
BeforeAdd=true

A
alexandrelss author 5/17/2010

Jane,
Sorry for the annoyance. ADD to the event was created, so that I could not do in EDIT. See the codes below.
--------------------------------------
'** Check if specific record exists ****

dim rsExists

set dal_table=dal.Table("categorias")

set rsExists = dal_table.Query("categoria='" & values("categoria") & "'","")

if not rsExists.eof then
BeforeAdd=false

message = "Esta categoria já foi cadastrada."
else

BeforeAdd = true
end if

rsExists.Close : set rsExists = Nothing
---------------------------------------------------------------------------------------

[color="#FF0000"]EDIT
dim rsExists

set dal_table=dal.Table("categorias")

set rsExists = dal_table.Query("categoria='" & values("categoria") & "'","")

if not rsExists.eof then
BeforeEdit=false

message = "Esta categoria já foi cadastrada."
else

BeforeEdit = true
end if

rsExists.Close : set rsExists = Nothing

A
alexandrelss author 5/17/2010

ADD OK

A
ann 5/19/2010

Hi,
you need to remove current record from SQL query in your event on the edit page. Here is just a sample:

set rsExists = dal_table.Query("categoria='" & values("categoria") & "' and ID<>" & keys("IDField"),"")