This topic is locked
[SOLVED]

 Check if specific record exists and....

12/28/2012 9:22:33 AM
ASPRunnerPro General questions
M
mitzi author

hello, here is my problem:
I know how to check if specific record exist but i do not know how to prevent duplicates.
situation(very simple):
two tables:
Table name: Main

ID

Date

Address

Description
Table2 name: Map

ID

Address

Map
On a daily basis I enter an address into the main table and save it

at the same time I insert automatically same address into the Table :"Map"
I would like to prevent duplicates in the table Map and also being able to add record to the main table.
how to do that?
In the Main table "before record added" what should I add:
I have a no idea what to start with.
there should be some clause like:
if record exists then - continue adding to main table, but not to the second table.

and if records does not exist add the record to both table.
please suggest

thanks

Sergey Kornilov admin 12/28/2012

Check if such a record exists first. Make bRecordExists variable store true if record exists and false in other case.
Add the following code to the end of BeforeAdd event:

if (bRecordExists) then

BeforeAdd=false

else

BeforeAdd=true

end if
M
mitzi author 12/31/2012

hi, i tired this in the AddPage Events area of the MAIN table - before record added:
'** Check if specific record exists ****

dim rsExists

set dal_table=dal.Table("Map")

set rsExists = dal_table.Query("Address='" & values("Address") & "'","")
if (bRecordExists) then

BeforeAdd=false

else

BeforeAdd=true

end if

rsExists.Close : set rsExists = Nothing
I could not add a record:
<<< Record was NOT added >>>
Item cannot be found in the collection corresponding to the requested name or ordinal.
PS. both table are empty by default.

M
mitzi author 1/3/2013

I guess I have to clarify the issue
I am entering the data into the MAIN table (where one of the fields is called Address)
I also automatically insert data into another table (Map) which also has the Address field)
It may so happen that I can again enter same address into the MAIN table when inserting another record, but I do not want to duplicate that address in the Map table.

also if the record in the Map table exists or does not exist NO matter, the MAIN table must add new record as usual.
Please help me to figure the code (events) out?
below is the add page of MAIN table before record added event
'** Check if specific record exists ****

dim rsExists

set dal_table=dal.Table("Map")

set rsExists = dal_table.Query("Address='" & values("Address") & "'","")
if (bRecordExists) then

BeforeAdd=false

else

BeforeAdd=true

end if

rsExists.Close : set rsExists = Nothing
I perfectly know that my code is worng , but i am very new to these please help.
logically :
check if the record exists in the Map table
if exists - do not add record to Map table but add record to MAIN(itself)
if not exist - continue adding record to the Map table

M
mitzi author 1/3/2013



Check if such a record exists first. Make bRecordExists variable store true if record exists and false in other case.
Add the following code to the end of BeforeAdd event:

if (bRecordExists) then

BeforeAdd=false

else

BeforeAdd=true

end if





hi, i tired this in the AddPage Events area of the MAIN table - before record added:
'** Check if specific record exists ****

dim rsExists

set dal_table=dal.Table("Map")

set rsExists = dal_table.Query("Address='" & values("Address") & "'","")
if (bRecordExists) then

BeforeAdd=false

else

BeforeAdd=true

end if

rsExists.Close : set rsExists = Nothing
I could not add a record:
<<< Record was NOT added >>>
Item cannot be found in the collection corresponding to the requested name or ordinal.
PS. both table are empty by default.


I finally tried this in the Before Record added
'** Check if specific record exists ****

dim bRecordExists

set dal_table2=dal.Table("GoogleMap")

set bRecordExists = dal_table2.Query("Address='" & values("Address") & "'","")
if (bRecordExists) then

BeforeAdd=false

else

BeforeAdd=true

end if

rsExists.Close : set rsExists = Nothing
and got nothing, ASPrunner application did the following:

  1. record was added to the main table(only after closing the popu window and refreshing the page)
  2. there was no rejection to the list page
  3. the record was not added to the googleMap table
    why?

Sergey Kornilov admin 1/4/2013

Here is the code that verifies if such Address exists in GoogleMap table and prevents record from being added if it does.

dim rsExists

set rsExists = CustomQuery("select Address from GoogleMap where Address='" & values("Address") & "'","")
if rsExists.eof then

BeforeAdd=true

else

BeforeAdd=false

end if

rsExists.Close : set rsExists = Nothing


If you also need to add a record into another table check DAL's Add() function:

http://xlinesoft.com/asprunnerpro/docs/add.htm

G
gdmacdo 1/7/2013

It appears as if you are checking the value in the Map table. If it exists, then you do not add the record in the Map table but you do wish to add it to the Main table.
The example below states that if the record exists in the Map table then skip adding a record to Map but still add it to the Main table. If it does not exist, add it to the Map table AND add it to the Main table.
dim bRecordExists

set dal_table2=dal.Table("Map")

set bRecordExists = dal_table2.Query("Address='" & values("Address") & "'","")
if (bRecordExists) then
[color="#ff0000"]else
[color="#ff0000"]dal_table2.Add()

BeforeAdd=true

end if

rsExists.Close : set rsExists = Nothing



I finally tried this in the Before Record added
'** Check if specific record exists ****

dim bRecordExists

set dal_table2=dal.Table("GoogleMap")

set bRecordExists = dal_table2.Query("Address='" & values("Address") & "'","")
if (bRecordExists) then

BeforeAdd=false

else

BeforeAdd=true

end if

rsExists.Close : set rsExists = Nothing
and got nothing, ASPrunner application did the following:

  1. record was added to the main table(only after closing the popu window and refreshing the page)
  2. there was no rejection to the list page
  3. the record was not added to the googleMap table
    why?

M
mitzi author 1/7/2013

Thank you Sergey and Greg for your great suggestions,
I have tried your solution as follows:
GoogleMap table: before record added event code:(no problems here)



dim rsExists

set dal_table=dal.Table("GoogleMap")

set rsExists = dal_table.Query("Address='" & values("Address") & "'","")
if not rsExists.eof then

--rbegin--' if record exists do something--rend--

BeforeAdd = false

message = "This address exists already"
else
--rbegin--' if not exist do something else--rend--

BeforeAdd = true

end if

rsExists.Close : set rsExists = Nothing


and

calmonthly table (which is my main table) Before record Added event (at the end, as Sergey previously mentioned):

(theme is the field that is equivalent to address field in GoogleMap table)



dim bRecordExists

set dal_table2=dal.Table("GoogleMap")

set bRecordExists = dal_table2.Query("Address='" & values("Theme") & "'","")
if (bRecordExists) then

BeforeAdd=true

else

dal_table2.Address=values("Address")
dal_table2.Add()

BeforeAdd=true

end if

rsExists.Close : set rsExists = Nothing


and got exactly where i was before:
When I attempt to add record, application does not save the record and does not insert any record in the google Map and alsoI have to click on the

"x" to close add window, then "refresh" to see that record was added to the calmonthly table. googlemap table remains empty even after that "operation"
Sergey, can I post the link to the demo application here?

G
gdmacdo 1/7/2013

If these are your real field names then change this line:
dal_table2.Address=values("Address")
to:
dal_table2.Address=values("Theme")



Thank you Sergey and Greg for your great suggestions,
I have tried your solution as follows:
GoogleMap table: before record added event code:(no problems here)
and

calmonthly table (which is my main table) Before record Added event (at the end, as Sergey previously mentioned):

(theme is the field that is equivalent to address field in GoogleMap table)
and got exactly where i was before:
When I attempt to add record, application does not save the record and does not insert any record in the google Map and alsoI have to click on the

"x" to close add window, then "refresh" to see that record was added to the calmonthly table. googlemap table remains empty even after that "operation"
Sergey, can I post the link to the demo application here?


M
mitzi author 1/7/2013

Thanks Greg, it not work either
try this link please admin/admin
http://demo.asprunner.net/mitzialexander2012_gmail_com/CalendarTest/login.asp

G
gdmacdo 1/7/2013

I do not see a "Theme" field on the add page.
http://demo.asprunner.net/mitzialexander2012_gmail_com/CalendarTest/calmonthly_add.asp



Thanks Greg, it not work either
try this link please admin/admin
http://demo.asprunne...rTest/login.asp


M
mitzi author 1/7/2013

hi, Greg,
the "theme" has the "address" as its label
the table is organized with theme as a field

however it is used to add actual address.
main table has theme as a field
googlemap has address as address field and correct label.

M
mitzi author 1/7/2013

project has several tables:
calcalendar is the main table, calmonthly is the view of the calcalendar table

googleMap is the additional table where i keep the mapped addresses.
I have tried to add the codes provided to the calmonthly view at the the end of the before add, and i also tried to add same code to the calcalendar table
something does not compute there.

  1. if I add the bRecordExists etc... to the calcalendar table - the record is being added to the calcalendar table and is displayed calmonthly view no problems

    BUT the googleMap has no records added.
  2. IfI have adone same thing to the calmonthly view - i get no records added(obviously) to none of the tables

M
mitzi author 1/7/2013

after numerous attempts i got this results:
'working version of adding duplicates to two tables

dim rsExists

set dal_table=dal.Table("GoogleMap")

'set rsExists = dal_table.Query("Address='" & values("Address") & "'","" ) not working

set rsExists = dal_table.Query("Address='Address'","")

if not rsExists.eof then

--rbegin--' if record exists do something--rend--

BeforeAdd = false

else
--rbegin--' if not exist do something else--rend--

dal_table.Address = values("Address")

dal_table.Add()

BeforeAdd = true

end if

rsExists.Close : set rsExists = Nothing
the application adds data to the main table,

adds data to the googlemap table
but
it still duplicates the data in the googlemap table <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=69240&image=1&table=forumreplies' class='bbc_emoticon' alt=':(' />

i see that there is a line dal_table.Add()
is there a something that would say da_table.DoNoTaDD() ??

G
gdmacdo 1/8/2013

Follow up (Solved):
This was the code that worked:
dim rsExists[/size][/font]

set dal_table=dal.Table("GoogleMap")
[color="#222222"]
[color="#222222"][font="arial, sans-serif"][size="2"]BeforeAdd =[color="#ff0000"] true[/size][/color]
[color="#222222"]

dal_table.Address = values("Address")[/size]

dal_table.Add()

BeforeAdd = true

end if

rsExists.Close : set rsExists = Nothing



after numerous attempts i got this results:
'working version of adding duplicates to two tables

dim rsExists

set dal_table=dal.Table("GoogleMap")

'set rsExists = dal_table.Query("Address='" & values("Address") & "'","" ) not working

set rsExists = dal_table.Query("Address='Address'","")

if not rsExists.eof then

--rbegin--' if record exists do something--rend--

BeforeAdd = false

else
--rbegin--' if not exist do something else--rend--

dal_table.Address = values("Address")

dal_table.Add()

BeforeAdd = true

end if

rsExists.Close : set rsExists = Nothing
the application adds data to the main table,

adds data to the googlemap table
but
it still duplicates the data in the googlemap table <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=69256&image=1&table=forumreplies' class='bbc_emoticon' alt=':(' />

i see that there is a line dal_table.Add()
is there a something that would say da_table.DoNoTaDD() ??

M
mitzi author 1/17/2013

Thank you dear Greg, it worked <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=69398&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />