Connecting Tech Pros Worldwide Forums | Help | Site Map

Can I use a Query stored in an MS Access database from an ASP page?

Noozer
Guest
 
Posts: n/a
#1: Jul 22 '05
Currently, I do the following in my ASP pages when making use of an MS
Access database:

Dim adoCon, rsSet, strSQL

Set AdoCon = server.CreateObject("ADODB.Connection")
Set RsSet = Server.CreateObject("ADODB.RecordSet")

adoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
Server.MapPath("MyDB.mdb")

strSQL="SELECT * FROM MyTable;"
rsSet.Open strSQL, adoCon
...do some stuff...
rsSet.Close
adoCon.Close

Set rsSet=Nothing
Set adoCon=Nothing

I have a couple queries stored in the database that I use when in MS Access.
Can I call these queries instead of using a string to specify the SQL
command?

The above seems kind of verbose for making use of a database. Can it be
simplified at all?

Thx!



Bob Barrows [MVP]
Guest
 
Posts: n/a
#2: Jul 22 '05

re: Can I use a Query stored in an MS Access database from an ASP page?


Noozer wrote:[color=blue]
> Currently, I do the following in my ASP pages when making use of an MS
> Access database:
>
> Dim adoCon, rsSet, strSQL
>
> Set AdoCon = server.CreateObject("ADODB.Connection")
> Set RsSet = Server.CreateObject("ADODB.RecordSet")
>
> adoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
> Server.MapPath("MyDB.mdb")
>
> strSQL="SELECT * FROM MyTable;"
> rsSet.Open strSQL, adoCon
> ...do some stuff...
> rsSet.Close
> adoCon.Close
>
> Set rsSet=Nothing
> Set adoCon=Nothing
>
> I have a couple queries stored in the database that I use when in MS
> Access. Can I call these queries instead of using a string to specify
> the SQL command?
>[/color]

Certainly.
For a non-parameter saved query, it's as simple as:

set rs=createobject("adodb.recordset")
adoCon.NameOfSavedQuery rs

if not rs.eof then ...

If the query uses parameters, see:
http://groups-beta.google.com/group/...d322b882a604bd

http://www.google.com/groups?hl=en&l...TNGP12.phx.gbl

http://groups.google.com/groups?hl=e...tngp13.phx.gbl




HTH,
Bob Barrows

Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


Closed Thread