02-11-2004, 18:19
|
|
|
חבר מתאריך: 20.12.01
הודעות: 20,962
|
|
בבקשה:
קוד:
<%
Dim oCon
Dim oRS
Dim sConStr
Dim sDBPath
Dim oSQLQuery
'We get the path of the MDB file(access database) through the Server.MapPath method which recieves a realtive path as an argument, and return ABSOLUTE path.
sDBPath = Server.MapPath ("db.mdb")
'We create the ADO Connection String:
'Provider tells ADO what type of data source we use. In our case it's OLEDB's access mechanism to MS Access Databases(The Access database engine is called Jet. first introduced around VB3 or VB4)
'Data Source, if using THIS provider is the path to the Access database MDB file, which we concatenate to sConStr from sDBPath, which holds the path.
'If we were using MS SQl Server, for instance, Data Source would be the machine name.
sConStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sDBPath
'We create new instanced of ADO's Connection(which connects us to the database), and Recordset(which gets the actual data) classes.
Set oCon = Server.CreateObject ("ADODB.Connection")
Set oRS = Server.CreateObject ("ADODB.RecordSet")
'We put our SQL Query here, to use later.
sSQLQuery = 'whatever you need
'We tell our connection, oCon, how to connect to the database by specifying the Connection String we prepared earlier, sConStr.
oCon.ConnectionString = sConStr
'We "open" the connection. This is the moment in which we actually connect to the database.
oCon.Open
'We specify to our Recordset, oRS, that the connection he should use is oCon.
oRS.ActiveConnection = oCon
'We execute the SQL Query we prepared eariler, sSQLQuery.
oRS.Open sSQLQuery
'From now on we can proccess the data in any way we want.
%>
|