View Full Version : open and close of a recordset
Hi I have to get the sum of a population for different values (i am looping through selections in a mulitselect) based on the individual items in the multiselect. I am opening and closing a recordset through each iteration of the loop bc i need values specific to that selection. My question is : Is it frowned upon to open and close a record set this way, or can i have one big record setand then try to manipulate the rs to get the values i need. I hope this makes sense. Thanks for the input
Freon22
05-07-2005, 02:43 AM
I am new to this board but, they say its best to close your recordset and db connection as fast as you can. It saves on server resources, I have also found that many times I will open a RS get the information that I need close it then open up another one then close that one. I never open and close my db connection more then once, unless I have to connect to a different db. I alway save my recordsets to variables so I can work with them later on the page. I am sure if you posted some of your code and sql statement here these guys would look at it and let you know if you are doing it the best way or not. I have been reading this board for a few days now and they seem to alway come through with the right help.
yeah I guess your right, although I am keeping the connection open and opening and closing the recordsets here what i'm thinking of in rough form, the bar & i variable stores the selection for the bar value (comes from a selection on the form), never tried this code or anything I only posted to show what I was thinking of doing with the recordset
for i = 1 to numofbars
rslabels.filter = (mid(base,3) + "_id = " + bar & i)
labels(i) = rslabels(mid(base,3))
rsdata.open "select sum(population) as sumpop from " + display_table &_
+ " where " + wherestr + " " + cstr(mid(base,3) + "_id") + " = " &_
cstr(bar & i),conn
data(i) = rsdata("sumpop")
rsdata.close
set rsdata = nothing
'this was used for testing
response.write("select sum(population) as sumpop from " + display_table &_
" where " + wherestr + " " + cstr(mid(base,3) + "_id") + " = " + cst &_
(request.form("bar" & i)))
next
Thanks for additional input
stupid me i found the conn.execute command
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.