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

Discussion in 'ASP General' started by Noozer, Jul 21, 2005.

  1. Noozer

    Noozer Guest

    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!
     
    Noozer, Jul 21, 2005
    #1
    1. Advertising

  2. 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/microsoft.public.inetserver.asp.db/msg/b3d322b882a604bd

    http://www.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=

    http://groups.google.com/groups?hl=...=1&selm=




    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"
     
    Bob Barrows [MVP], Jul 21, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brenda Pasquarello

    MS Access Query - use like stored procedure?

    Brenda Pasquarello, Mar 7, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    3,738
    Michael Bohman
    Mar 8, 2006
  2. =?Utf-8?B?U1M=?=
    Replies:
    3
    Views:
    3,878
    Juan T. Llibre
    May 15, 2005
  3. Doug
    Replies:
    3
    Views:
    4,410
    Bruce Barker
    Nov 4, 2005
  4. George Stout
    Replies:
    4
    Views:
    223
    George Stout
    Jan 21, 2004
  5. Jack
    Replies:
    1
    Views:
    176
    Bob Barrows [MVP]
    Dec 16, 2004
Loading...

Share This Page