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

This is Interesting: Free IT Magazines  
Home > Archive > IIS ASP > July 2005 > Can I use a Query stored in an MS Access database from an ASP page?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

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

2005-07-21, 7:48 am

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]

2005-07-21, 7:48 am

Noozer wrote:
> 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?
>


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...3d322b882a604bd

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

http://groups.google.com/groups?hl=...ftngp13.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"


Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com