Google Answers Logo
View Question
 
Q: visual basic 6.0, MS Access, ADO ( No Answer,   1 Comment )
Question  
Subject: visual basic 6.0, MS Access, ADO
Category: Computers > Programming
Asked by: snapril-ga
List Price: $5.00
Posted: 11 Nov 2003 15:08 PST
Expires: 11 Dec 2003 15:08 PST
Question ID: 274885
I want to connect using ADO to an Access Database.  Both files on same machine
No need for secuirty.  Both the Program and DB on same machine.

How do I connect
Answer  
There is no answer at this time.

Comments  
Subject: Re: visual basic 6.0, MS Access, ADO
From: steverino-ga on 17 Nov 2003 07:49 PST
 
Your question is vauge re. what you want to use to connect to Access
via ADO:  what technology are you using to connect to Access?

Here are two connection methods:

ASP connection to Access (for a web page):

<%
'-- Declare your variables
Dim DataConnection, myRS, DBFileName

' Change the db1.mdb to <yourfilename>.mdb
DBFileName = "MyDB.mdb"

'-- Create dataconnection and recordset object and open database

Set DataConnection = Server.CreateObject("ADODB.Connection")
Set myRS = Server.CreateObject("ADODB.Recordset")
DataConnection.Open = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source="
& Server.MapPath("\") & "\MyDB.mdb;"

%>

COMMENTS:  this is a DSN-less connection, which means you don't have
to set up a reference to the Access db in the ODBC control panel,
which means less maintenance overhead for the server and less
processing resources for creating the connection needed.  The
Server.MapPath stuff allows you to make a relative reference to the
Access db (as long is it is in the webserver Root or a subfolder). 
After setting up the commands to open the db as DataConnection, you
will need to write an appropriate SQL statement and create a
recordset:

mySQL = "SELECT [fields] FROM [TABLE] WHERE [Condition];"

myRS.Open mySQL, DataConnection, adOpenStatic, adCmdTable 
Conmment: the last two specifications are Cursor type declaration
(OpenStatic) and what object is being operated on in the
DataConnection (CmdTable).  Depending on your needs, you may want
other cursor types, etc.

****

ADO in Access

You can also try to connect to an Access db in Access (VBA) and ADO is
a way to do it, but DAO is recommended.  Using DAO for connection in
VBA to an Access table is trivial:

    Dim rst As DAO.Recordset
     
    ' Access the query results
    Set rst = CurrentDb.OpenRecordset("TableName", dbOpenDynaset)

COMMENTS:  this illustrates connection using DAO in an Access VBA
module to open a table in the same database.  Notice Set rst =
CurrentDB.  Also the table name and cursor type is specified in the
parenthesis.  If you want to connect to another Access db you will
have to supply information for that db and, as in the ASP example, you
may need to assign a cursor to your recordset that is good for your
purposes.

ASP is generic enough to transfer to other technologies, so it is
useful to understand, even if you are not using ASP to connect to
Access.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy