Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: Urgent help needed for updating a recordset


Message #1 by "Eric Van Camp" <eric@a...> on Wed, 25 Apr 2001 15:25:31 +0200
hi,

i want to update a recordset with new information,BUT BEFORE i update i need

to check whether this information already exists in the database!

I first check whether endof and beginningof the recordset are equal, meaning

that the recordset is empty, but then i want to add /update the information

in the database!

my code******************

rem***store the mutiple select values in an array

dim array

array=split(upl.form("idlistings"),",")

rem***now check whether the information is already in the database!

rem***do this every time you have a value in the array

Set rslistings = Server.CreateObject("ADODB.Recordset")

for i=0 to Ubound(array)

	Set rslistings = Server.CreateObject("ADODB.Recordset")

	sqlistings="select * from emailistings where idemail="&mail_id&" and

idlistings="&array(i)

	response.write sqListings

	rslistings.open sqlistings,db,adLockOptimistic,adOpenDynamic,AdCmdtext

	if  not rslistings.eof then

		response.write "entry"

	else

		response.write "no entry"

		sqlistings2="select idlistings,idemail from emailistings"

		Set rslistings2 = Server.CreateObject("ADODB.Recordset")

		rslistings2.open sqlistings2,db,adLockOptimistic,adOpenDynamic,AdCmdtext

		response.write sqlistings2

		rslistings2.AddNew

		rslistings2("idlistings")=array(i)

		rslistings2("idemail")=mail_id

		rslistings2.update

		rslistings2.close

		set rslistings2=nothing

	end if

	rslistings.close

	set rslistings=nothing

next

rem******end of code

I know this works but i wonder whether there is a way to use less resources?



Met Vriendelijke groet,

Eric Van Camp

Atmilestone BVBA

Trolieberg 74

3010 Kessel-lo

Tel:016/35.69.99

Fax:016/35.57.90

eric@a... <mailto:eric@a...>





 <http://www.atmilestone.be/>





Message #2 by "Eric Landes" <elandes@p...> on Wed, 25 Apr 2001 12:53:59 -0500
Why not use the same recordset to check and update?  Although I don't know

that you are necessarily wasting a ton of resources.  Have you used WAST to

stress test the application?



but what I might do is something like this:

Set rslistings = Server.CreateObject("ADODB.Recordset")

for i=0 to Ubound(array)

	Set rslistings = Server.CreateObject("ADODB.Recordset")

	sqlistings="select * from emailistings where idemail="&mail_id&" and

idlistings="&array(i)

	response.write sqListings

	rslistings.open

sqlistings,db,adLockOptimistic,adOpenDynamic,AdCmdtext

	if  not rslistings.eof then

		response.write "entry"

	else

		response.write "no entry"

		rslistings.close

----- MY CHANGES -------

		sqlistings="select idlistings,idemail from emailistings"

		rslistings.open

sqlistings,db,adLockOptimistic,adOpenDynamic,AdCmdtext

		response.write sqlistings

		rslistings.AddNew

		rslistings("idlistings")=array(i)

		rslistings("idemail")=mail_id

		rslistings.update

		rslistings.close

	end if

----- END OF MY CHANGES  -----



	set rslistings=nothing

next



HTH

*************************

Eric Landes

SQL Programmer/Web Developer

*************************

All statements expressed are my own, and do not reflect the opinion of

my employer, unless stated otherwise.  









> -----Original Message-----

> From: Eric Van Camp [mailto:eric@a...]

> Sent: Wednesday, April 25, 2001 10:37 AM

> To: ASP Databases

> Subject: [asp_databases] Urgent help needed for updating a recordset

> 

> 

> hi,

> i want to update a recordset with new information,BUT BEFORE 

> i update i need

> to check whether this information already exists in the database!

> I first check whether endof and beginningof the recordset are 

> equal, meaning

> that the recordset is empty, but then i want to add /update 

> the information

> in the database!

> my code******************

> rem***store the mutiple select values in an array

> dim array

> array=split(upl.form("idlistings"),",")

> rem***now check whether the information is already in the database!

> rem***do this every time you have a value in the array

> Set rslistings = Server.CreateObject("ADODB.Recordset")

> for i=0 to Ubound(array)

> 	Set rslistings = Server.CreateObject("ADODB.Recordset")

> 	sqlistings="select * from emailistings where 

> idemail="&mail_id&" and

> idlistings="&array(i)

> 	response.write sqListings

> 	rslistings.open 

> sqlistings,db,adLockOptimistic,adOpenDynamic,AdCmdtext

> 	if  not rslistings.eof then

> 		response.write "entry"

> 	else

> 		response.write "no entry"

> 		sqlistings2="select idlistings,idemail from 

> emailistings"

> 		Set rslistings2 = Server.CreateObject("ADODB.Recordset")

> 		rslistings2.open 

> sqlistings2,db,adLockOptimistic,adOpenDynamic,AdCmdtext

> 		response.write sqlistings2

> 		rslistings2.AddNew

> 		rslistings2("idlistings")=array(i)

> 		rslistings2("idemail")=mail_id

> 		rslistings2.update

> 		rslistings2.close

> 		set rslistings2=nothing

> 	end if

> 	rslistings.close

> 	set rslistings=nothing

> next

> rem******end of code

> I know this works but i wonder whether there is a way to use 

> less resources?

> 

> Met Vriendelijke groet,

> Eric Van Camp

> Atmilestone BVBA




  Return to Index