| Home | Family | Softwares | Resume | Activities |
A SIMPLE APPLICATION TO DISPLAY DATA FROM AN ACCESS DATABASE TABLE
<!-- #Include file=
"adovbs.inc"-->
'Every thing inside the <% and %>
tags is the ASP code.
<% Response.buffer = true %>
'Above line indicates to the server that only when the execution
of the whole page is 'complete then sent the content to the client browser.
Setting this value to 'false' will mean 'that the content will be send to the
client browser as soon as the page execution starts. 'This tag actually plays no
part in our database tutorial so just ignore
it.
<html>
<head>
<title>Database
Tutorial</title>
</head>
<body>
<% Dim rs
Set rs =
Server.CreateObject ("ADODB.Recordset")
'We create
a variable 'rs' and then initilize it to point it to 'ADODB.Recordset'
'component. It is this 'ADODB.Recordset' component which we are using to display
the 'contents of our database.
rs.Open "names",
"DSN=odbc_exmp"
'We then use the 'Open' method of our
'rs' object ( which points to ADODB.Recordset 'component ) to open our database.
We give it two arguments, "names" for the name of 'the table in our database and
"DSN=odbc_exmp" for the name of DSN to use.
While Not
rs.EOF
Response.Write "ID : " & rs("id") &
"<br>"
Response.Write "First Name : " & rs("first_name") &
"<br>"
Response.Write "Last Name : " & rs("last_name") &
"<br>"
Response.Write
"<br>"
rs.MoveNext
Wend
rs.Close
Set rs = Nothing
%>
</body>
</html>
ADO : DIFFERENT METHODS THROUGH ASP FILE
NAME OF
FILE FIRST.ASP
ADO SERVER SIDE : OPENING OF CONNECTIONS
Set cn =
Server.CreateObject("ADODB.Connection")
Set rs =
Server.CreateObject("ADODB.Recordset")
METHOD 1 :
cn1.Open
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath
("../telephone/telephone.mdb") & ";"
rs1.Open "select * from
telephone",cn1, adOpenKeyset , ,adcmdText
METHOD 2
:
cn2.Provider = "Microsoft.Jet.OLEDB.3.51"
cn2.Open
("d:\ravi\telephone\telephone.mdb")
METHOD 3 :
cn4.Open
"Beta2"
Set rs4 = cn4.Execute("select * from
customer")
METHOD 4 :
cn5.Open ("dsn=
beta2;userid=;password=")
Set rs5 = cn5.Execute("select * from
customer")
METHOD 5 :
a = "beta2"
b =
"can=directory manager"
c = "password"
cn3.Open a, b,
c
Set rs3 = cn3.Execute("select * from customer")
METHOD
6
Set cnn2 = New ADODB.Connection
cnn2.ConnectionString="DSN=Pubs;UID=sa;PWD=pwd;"
cnn2.Open
METHOD 7 :
Set cnn3 = New
ADODB.Connection
cnn3.ConnectionString = "Data Source=
Pubs;UserID=sa;Password=pwd;"
cnn3.Open
METHOD 8 :
Set cnn4 = New
ADODB.Connection
cnn4.Open "Pubs", "sa", "pwd"
CONNECT
WITHOUT USING DSN
METHOD 1
FOR ALL CODES IT IS
ESSENCIAL TO SET AN OBJECT AS
SET cn = NEW ADODB.CONNECTION
cn.Open "PROVIDER=MSDASQL;" &
_
"DRIVER={Microsoft Access Driver (*.mdb)};" &
_
"server=monaco;DBQ=d:/ravi/PSPL_Access/pspl.mdb;" &
_
"UID=admin;PWD=;"
Set rs = cn.Execute("select * from
Betainform")
MsgBox rs.Fields(1).Value
cn.ConnectionString
= "driver={SQL Server};" &
_
"server=202.54.11.73;uid=sa;pwd=sql"
cn.Open
cn.DefaultDatabase =
"telephone"
Set rs = cn.Execute("select * from
telephone")
MsgBox rs.Fields(1).Value
cn.Open
"PROVIDER=MSDASQL;" & _
"DRIVER={Microsoft Access Driver (*.mdb)};"
& _
"server=monaco;DBQ=d:/ravi/PSPL_Access/pspl.mdb;" &
_
"UID=admin;PWD=;"
Set rs = cn.Execute("select * from
Betainform")
MsgBox rs.Fields(1).Value