PDA

Click to See Complete Forum and Search --> : Urgent : Using ADO To Gain Access To A MS-Access Database.


omarswan
Jan 6th, 2000, 12:34 PM
Is it possible to use ADO To Gain Access To A MS-Access Database on a Web-Site Using VB??
If so How?

------------------
OmarSwan

omarswan@yahoo.com

http://omarswan.da.ru/

"Jesus is Lord"

kandan
Jan 6th, 2000, 01:40 PM
hi,

ya it is possible to gain access to ms_access using ADO..this is the sample code below where i used disconnected recordset...

paste this code in any module.............
Public Function Testrecordset() As ADODB.Recordset
Dim adors As ADODB.Recordset
Dim adocn As ADODB.Connection

Dim strconnection As String

Set adocn = New ADODB.Connection
strconnection = "DRIVER=Microsoft Access Driver (*.mdb);dbq=c:\db_library.mdb;"
adocn.Open strconnection

Set adors = New ADODB.Recordset
adors.ActiveConnection = adocn

adors.CursorLocation = adUseClient
adors.Open ssql

If UCase(Trim(Left(ssql, 6))) = "SELECT" Then
Set adors.ActiveConnection = Nothing
Set Testrecordset = adors.Clone
adors.Close
adocn.Close
Set adors = Nothing
Set adocn = Nothing
Else
Set Testrecordset = Nothing
End If
End Function
**********
paste this code in ur form n pass this paramter...declaring ssql as a PUBLIC VARIABLE in the module.....
ssql = "select * from tbl_book"
Set adors = Testrecordset

hope this might help uuu..
if still any doubts ask meee..

kandan.

Clunietp
Jan 6th, 2000, 01:44 PM
that's wonderful if he can access the database like he would if it were on his C drive, but I think he means he wants to break security on an existing site to get to a database, or he wants to use ASP to display information on his own web page with data from a MS Access Db....

???

Jan 6th, 2000, 03:49 PM
...and the easy way:
(assuming you're using vb)

option explicit

dim conYourConnection As ADODB.Connection
dim recYourRecordSet As ADODB.Recordset
dim strYourConnectionString As String
dim strYourSqlStatement As String
dim strFullPathToDatabase As String


public sub AdoAccessTest()
strFullPathToDatabase = "c:\YourAccessDatabaseName.mdb"
Set conYourConnection = New ADODB.Connection
conYourConnection.ConnectionString = "{Microsoft Access Driver (*.mdb)};DBQ=" & strFullPathToDatabase
conYourConnection.Open
strYourSqlStatement = "SELECT * FROM YourAccessTable"
Set recYourRecordSet = New ADODB.Recordset
recYourRecordSet.Source = strYourSqlStatement
recYourRecordSet.ActiveConnection = conYourConnection
recYourRecordSet.Open
if not(recYourRecordSet.bof and recYourRecordSet.eof) then
do while not recYourRecordSet.eof
debug.print recYourRecordSet("NameOfAField")
recYourRecordSet.MoveNext
loop
'clean up
set recYourRecordset = nothing
set conYourConnection = nothing
end sub


keep in mind this is a DSN-less connection. You can use the same thing in ASP, you just need to modify the path. If you're using ASP on another host the relative path to your database might be http://www.yoursite.com/yourdatabase.mdb but the absolute path could be f:\somedirectory\somesubdirectory\someotherdirectory\yourdatabase.mdb
...to avoid problems in ASP use the following:

strFullPathToDatabase = Server.MapPath("http://www.yoursite.com/yourdatabase.mdb")

...the full absolute path as it exists on the server will be translated from the url along with the name of the database.

-good luck