Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Multiple queries on same page
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Multiple queries on same page

 Post Reply Post Reply
Author
jrockfl View Drop Down
Newbie
Newbie


Joined: 03 February 2003
Location: United States
Status: Offline
Points: 28
Post Options Post Options   Thanks (0) Thanks(0)   Quote jrockfl Quote  Post ReplyReply Direct Link To This Post Topic: Multiple queries on same page
    Posted: 20 June 2003 at 10:46am

What would be the correct way to have more then one query on a page. Here is the code I am using for just one query. I would like to add more, I just want to make sure I am doing things correctly.

<%
'Dimension Variables
Dim adoCon 'Holds the database connection object
Dim rsService 'Holds the recordset for the records in the database
Dim strSQL 'Holds the SQL query

'Create an ADO connection object
Set adoCon = Server.CreateObject("ADODB.Connection")

'Create an active connection to the connection object
adoCon.Open "DSN=rockenbach"

'Create an ADO recordset object
Set rsService = Server.CreateObject("ADODB.Recordset")

'Initialize the strSQL variable with an SQL query
strSQL = "SELECT servicesid, service FROM r_services ORDER BY sort asc"

'Open the recordset with SQL query
rsService.Open strSQL, adoCon
%>

Back to Top
MorningZ View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 May 2002
Location: United States
Status: Offline
Points: 1793
Post Options Post Options   Thanks (0) Thanks(0)   Quote MorningZ Quote  Post ReplyReply Direct Link To This Post Posted: 20 June 2003 at 10:53am

either use, then close that recordset.. and reuse it...

or create another recordset with the new query

Contribute to the working anarchy we fondly call the Internet
Back to Top
jrockfl View Drop Down
Newbie
Newbie


Joined: 03 February 2003
Location: United States
Status: Offline
Points: 28
Post Options Post Options   Thanks (0) Thanks(0)   Quote jrockfl Quote  Post ReplyReply Direct Link To This Post Posted: 20 June 2003 at 11:42am

Something like this? I created another recordset and query

<%
'Dimension Variables
Dim adoCon 'Holds the database connection object
Dim rsService 'Holds the recordset for the records in the database
Dim rsPortfolio 'Holds the recordset for the records in the database
Dim strSQL 'Holds the SQL query
Dim strSQL2 'Holds the SQL query

'Create an ADO connection object
Set adoCon = Server.CreateObject("ADODB.Connection")

'Create an active connection to the connection object
adoCon.Open "DSN=rockenbach"

'Create an ADO recordset object
Set rsService = Server.CreateObject("ADODB.Recordset")
Set rsPortfolio = Server.CreateObject("ADODB.Recordset")

'Initialize the strSQL variable with an SQL query
strSQL = "SELECT servicesid, service FROM r_services ORDER BY sort asc"
strSQL = "SELECT * FROM portfolio"

'Open the recordset with SQL query
rsService.Open rsPortfolio.Open strSQL,strSQL2, adoCon
%>

Back to Top
ljamal View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 16 April 2003
Status: Offline
Points: 888
Post Options Post Options   Thanks (0) Thanks(0)   Quote ljamal Quote  Post ReplyReply Direct Link To This Post Posted: 20 June 2003 at 2:51pm
Is the DSN pointing to a Access DB or SQLServer?

With SQL you can return multiple recordsets with a single query. So you could do

strSQL = "select servicesID, service from r_services order by sort asc; select * from portfolio"
set rsSQL = sqlConn.Execute(strSQL)

where sqlConn is your open SQL Server Conn and rsSQL is a recordset. By default the first recordset is open (select servicesID, service from r_services order by sort asc) and to move to the next recordset you would use:
Set rsSQL = rsSQL.NextRecordSet()
and then you could access the other recordset (select servicesID, service from r_services order by sort asc)

If you are using SQL Server, my suggestion to learn and use the above method as it reduces your SQL server calls and thus the rendering time for the page.
Back to Top
jrockfl View Drop Down
Newbie
Newbie


Joined: 03 February 2003
Location: United States
Status: Offline
Points: 28
Post Options Post Options   Thanks (0) Thanks(0)   Quote jrockfl Quote  Post ReplyReply Direct Link To This Post Posted: 20 June 2003 at 9:15pm

I understand what you are saying with SQL Server. I am using Access though. What would be good practice for Access with mulitple queries?

Back to Top
ljamal View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 16 April 2003
Status: Offline
Points: 888
Post Options Post Options   Thanks (0) Thanks(0)   Quote ljamal Quote  Post ReplyReply Direct Link To This Post Posted: 20 June 2003 at 9:20pm
Access does not allow the return of multiple recordsets with a single query. My suggestion is always to open and close database connections ASAP. Usually, I make all my database calls at the top of an ASAP page, store to a detached recordset or array and then use the array or recordset when need in the page. I lean towards array because they make moving through (forwards and backwards) recordsets easier.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.