Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Topics covered
PLATFORM USED WHAT IS ADO? What is ODBC? ADO, ODBC and OLE DB What is ADODB? Accessing a Database from an ASP Page
PLATFORM
Operating system- Windows Xp Back End Microsoft Office Access 2003 Database Front End ASP Access stores data in its own format based on the Access Jet Database Engine Jet is the Database Management System ( DBMS ) which underlies Microsoft Access Data is stored in the form of .mdb files
(database engine or "storage engine" is the underlying software component that a (DBMS) uses to create, read, update and delete data from a database)
ADO
OLE DB
RDBMS
Directory Services
5
What is ODBC?
ODBC (Open Database Connectivity) is an API specification that provides a way for client programs (eg Visual Basic, Excel, Access, etc) to access multiple database systems using SQL ODBC-standard software interface for accessing DBMS that uses SQL The ODBC Driver resides between the ODBC Client and the DBMS Any ODBC-compliant application can access any DBMS that has a corresponding driver.
Confused !!!!....?
Lets go into little more detail
JET
SQL
Oracle
ODBC
OLE DB Providers
JET
SQL
Oracle
ODBC Drivers
Access
SQL
Oracle
Access
SQL
Oracle
Cont.
What the diagram explains?
OLE DB programming interface interacts with OLEDB data providers similarly to the way the ODBC API interacts with ODBC drivers-both OLEDB data provider and ODBC drivers provide direct access to specific data stores. Although ODBC drivers available for most popular DBMS, OLE DB is there for limited set of popular DBMS. To provide programmers access to both DBMS ,MS provided OLEDB provider for ODBC drivers.
10
What is ADODB?
ADODB(ActiveX Data Objects for Database) is an abstraction library adodb is a collection of methods to access the data from the Database Application developed using Microsoft Visual Studio ADODB supports-ADO,MYSQL,Oracle,MS SQL Sever,etc - it uses SQL
ADODB Objects
Connection
RecordSet
Command
11
12
13
Creating a Connection
Connection objects are created using the CreateObject() function. <%
Dim ObjConn create a variable to hold a reference to the object Set ObjConn=Server.CreateObject(ADODB.Connection)
%>
14
15
1) If ConnectionString is used
Once the ConnectionObject created ,we need to give it a ConnectionString to logon to the datasource ConnectionString specifies the : provider datasource name userid (optional) password (optional) Dim cnn Dim str str = Provider=MSDASQL; Data Source=mydatasource; User Id=;Password= cnn.ConnectionString = str
17
str = Provider=MSDASQL.1,Data Source=mydatasource; str = str & User ID=myuserid;Password=mypass cnn.ConnectionString = str
cnn.Open
..cnn.Close
18
2) If DSN is used . . .
<% Set MyConn=Server.CreateObject("ADODB.Connection") MyConn.Open "FILEDSN=c:\dsn\MyTable_dsn.dsn ... MYConn.close %>
19
20
RS.ActiveConnection = MyConn
RS.Open SQL_query
or
OR Set RS = MyConn.Execute(SQL_query)
22
23
<table border="1" width="100%"><tr> <%for each x in RS.Fields Response.Write("<th>" & x.name & "</th>") next%></tr> <%do until RS.EOF%> <tr> <%for each x in RS.Fields%><td><%Response.Write(x.value)%></td> <%next RS.MoveNext%> </tr> <%loop ...
(
for page 3 )
25
26
Page 1
Page 2
Page 3
Page 1
<HTML> <BODY> <form action="page2.asp" method="get"> <p>Please Enter the Table to display:</p> <input type="radio" name="tablename" value="Friends">Friends</input> <br /> <input type="radio" name="tablename" value="Saab">Subjects</input> <br /> <input type="radio" name="tablename" value="BMW">Family</input> <br /><br /><br /><br /> <input type="submit" value="Submit" /> </form> </BODY> </HTML>
30
Page 2
<HTML> <% dim tablename tablename=Request.QueryString("tablename") %> <BODY> <p>Please Enter the fields to Display :</p><br/><br/><br/> <form action="page3.asp" method="get"> <% Set MyConn = Server.CreateObject("ADODB.Connection") MyConn.Open "FILEDSN=c:\dsn\MyTable_dsn.dsn" SQL_query = "SELECT * FROM " & tablename Set rs = MyConn.Execute(SQL_query) %>
31
Page 2
You choosed : <input type="radio" name="tablename" value="<%Response.Write(tablename)%>" CHECKED><%Response.Write(tablename)%></input> <br/><br/><tr> <%for each x in rs.Fields %><th> <input type="checkbox" name="column" value="<%Response.Write(x.name)%>"><%Response.Write(x.name)%></input > </th><%next%> </tr></table> <% rs.close Set rs = Nothing MYConn.close Set MyConn = Nothing %> <br /><br /> <input type="submit" value="Submit" /></form> </BODY> </HTML>
32
Page 3
<HTML><% dim tablename dim column tablename=Request.QueryString("tablename") column=Request.QueryString("column")%> <BODY> <B>Here are my friends:<B><BR> <% Set MyConn = Server.CreateObject("ADODB.Connection") MyConn.Open "FILEDSN=c:\dsn\MyTable_dsn.dsn" SQL_query = "SELECT " & column & " FROM " & tablename Set RS = MyConn.Execute(SQL_query)%> <table border="1" width="100%"><tr> <%for each x in RS.Fields Response.Write("<th>" & x.name & "</th>") next%></tr>
33
Page 3 . . .
<%do until RS.EOF%> <tr> <%for each x in RS.Fields%> <td><%Response.Write(x.value)%></td> <%next RS.MoveNext%></tr><%loop RS.close Set RS = Nothing MYConn.close Set MyConn = Nothing %> <% if tablename<>"" then Response.Write("<p>Entered table is: " & tablename & "</p>") Response.Write("<p>Entered coloumn is: " & column & "</p>") end if %></BODY></HTML>
34
!!Thank you!!
35