Asp ADO

download Asp ADO

of 35

Transcript of Asp ADO

  • 8/3/2019 Asp ADO

    1/35

    Dynamic database query generator

    for the administrator. Ask user thetable, fields he wants to access.

    Payal R. ChaudharyU07CO237Purvi R. Chaudhary

    U07CO241SVNIT,Computer

    department 1

  • 8/3/2019 Asp ADO

    2/35

    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

    2

  • 8/3/2019 Asp ADO

    3/35

    PLATFORM

    Operating system- Windows Xp

    Back EndMicrosoft Office Access 2003 Database

    Front EndASP

    Access stores data in its own format based on the Access Jet DatabaseEngine

    Jet is the Database Management System ( DBMS ) which underlies MicrosoftAccess

    Data is stored in the form of .mdb files

    (database engine or "storage engine" is the underlying software componentthat a (DBMS) uses to create, read, update and delete data from adatabase)

    3

  • 8/3/2019 Asp ADO

    4/35

    ActiveX Data Objects (ADO)

    ADO is Microsoft Technology

    ADO stands for ActiveX Data Objects

    ADO is a Microsoft ActiveX Component

    ADO is automatically installed with Microsoft IIS

    ADO is a programming interface to access data in a database

    ( without knowing how the Database is implemented )

    4

  • 8/3/2019 Asp ADO

    5/35

    ADO Software Architecture

    5

    VC++ VB Script Java

    ADO

    OLE DB

    RDBMS E-mail Directory Services

  • 8/3/2019 Asp ADO

    6/35

    What is ODBC?

    ODBC (Open Database Connectivity) is an API specification thatprovides a way for client programs (eg Visual Basic, Excel, Access, etc) to

    access multiple database systems using SQL

    ODBC-standardsoftware interface for accessing DBMS that uses SQL

    The ODBC Driverresides between the ODBC Client and the DBMS

    Any ODBC-compliant application can access any DBMS that has acorresponding driver.

    6

  • 8/3/2019 Asp ADO

    7/35

    ADO, ODBC and OLE DB

    ODBC was the MS wayof connecting to and using databases on theWindows platform

    ADO is the strategic way for using ODBC data sources on the Windows

    platform

    OLE DB extends ODBC by using the concept of service providers to add the

    ability to connect to other non-database data sources (MS Active Directory(LDAP), e-mail servers (Exchange)) that do not necessarily use SQL.

    ODBC Data Sources; provider = MSDASQL

    MS Index Server; provider = MSIDXS

    MS Active Directory Server - provider = ADSD300Object

    MS Jet databases - provider = Microsoft.Jet.OLEDB.3.51

    MS SQL Server - provider = SQLOLEDB

    Oracle Databases - provider = MSDAORA

    7

  • 8/3/2019 Asp ADO

    8/35

    Confused !!!!....?

    Lets go into little more detail

    8

  • 8/3/2019 Asp ADO

    9/35

    Providers and Drivers

    9

    ADO

    JET SQL Oracle

    JET SQL Oracle

    ODBC

    Access SQL Oracle Access SQL Oracle

    OLE DB

    Providers

    ODBC

    Drivers

    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 , Microsoft provided OLEDB provider for ODBC drivers Called

    MSDASQL

  • 8/3/2019 Asp ADO

    10/35

    Cont.

    10

    What the diagram explains?

    OLE DB programming interface interacts with OLEDB data providers similarlyto the way the ODBC API interacts with ODBC drivers-both OLEDB dataprovider 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 OLEDBprovider for ODBC drivers.

  • 8/3/2019 Asp ADO

    11/35

    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

    11

    ADODB Objects

    Connection RecordSet Command

  • 8/3/2019 Asp ADO

    12/35

    Accessing a Database from an ASP Page(Steps)

    Create an ADO connection to a database Open the database connection Create an ADO recordset Open the recordset Extract the data you need from the recordset Close the recordset

    Close the connection

    Steps explained in detail for clear understanding.

    12

  • 8/3/2019 Asp ADO

    13/35

    STEP 1 :Creating instance of

    ConnectionADODB Connection object- open up an ODBC/OLEDB

    Connection to a database through database drivers so

    you can do something with the database.

    Server Object- ASP object used to access properties and

    methods on the server

    13

  • 8/3/2019 Asp ADO

    14/35

    Creating a Connection

    Connection objects are created using the

    CreateObject() function.

    14

  • 8/3/2019 Asp ADO

    15/35

    Connection object required

    15

  • 8/3/2019 Asp ADO

    16/35

    STEP 2 : Open up a database

    How???!!!!!!

    By using using1) a Connection String (DSN-less) or2) Data Source Name ( DSN )Usually used is Connection String

    Establish a connection string and Open it Here we useDSN

    16

  • 8/3/2019 Asp ADO

    17/35

    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)

    17

    Dim cnn

    Dim str str = Provider=MSDASQL; Data Source=mydatasource;

    User Id=;Password=

    cnn.ConnectionString = str

  • 8/3/2019 Asp ADO

    18/35

    Open() and Close()

    Once the connection established , the Connection must beopened before using it

    Likewise it should be closed when done.

    18

    Dim cnn

    Dim str

    Set cnn = CreateObject(ADODB.Connection)

    str = Provider=MSDASQL.1,Data Source=mydatasource;

    str = str & User ID=myuserid;Password=mypass

    cnn.ConnectionString = str

    cnn.Open

    ..cnn.Close

  • 8/3/2019 Asp ADO

    19/35

    2) If DSN is used . . .

  • 8/3/2019 Asp ADO

    20/35

    DSN-Data Source Name

    20

    data structure that contains information about a specific database that an

    ODBC driver needs in order to connect to it.(ex:- driver,directory,name as thedatabase,user ID)

    A file DSN contains the relevant

    information within a text file with a

    .dsn file extension , and can be sharedby users of different computers who

    have the same drivers installed.(unlike

    system and user DSN)

  • 8/3/2019 Asp ADO

    21/35

    STEP 3 : CREATE AN ADO RECORDSET

    Record set objects are the recipients of the result of a SQL query

    create the Connection object then create a recordset object and associate

    them

    21

    Dim MyConn

    Dim RS

    set MyConn = CreateObject(ADODB.Connection)

    set RS = CreateObject(ADODB.Recordset)

    assocoate the record set with the connection

    RS.ActiveConnection = MyConn

  • 8/3/2019 Asp ADO

    22/35

  • 8/3/2019 Asp ADO

    23/35

    Step 5 : Extract the data you need

    from the recordset

    23

    The record set is a collection of rows, each row containing the data

    in the order that it was asked for in the SQL statement, each column

    in the row can be accessed by its column name

    User chooses table by simple radio botton, which gets passed to

    next page stored in a variable

  • 8/3/2019 Asp ADO

    24/35

    Getting Data out

    Displaying field names of table in checkboxesfor user to

    Choose

  • 8/3/2019 Asp ADO

    25/35

    Displaying table with field names and values

  • 8/3/2019 Asp ADO

    26/35

    Code and Output (Screenshots)

    26

  • 8/3/2019 Asp ADO

    27/35

    Page 1

  • 8/3/2019 Asp ADO

    28/35

    Page 2

  • 8/3/2019 Asp ADO

    29/35

    Page 3

  • 8/3/2019 Asp ADO

    30/35

    Page 1

    Please Enter the Table to display:

    Friends


    Subjects


    Family





    30

  • 8/3/2019 Asp ADO

    31/35

    Page 2

    Please Enter the fields to Display :




    31

  • 8/3/2019 Asp ADO

    32/35

    Page 2

    You choosed :





    32

  • 8/3/2019 Asp ADO

    33/35

    Page 3

    Here are my friends:

    33

  • 8/3/2019 Asp ADO

    34/35

    Page 3 . . .

    34

  • 8/3/2019 Asp ADO

    35/35

    !!Thank you!!

    35