asp ado sql 2000

Upload: unta09

Post on 07-Apr-2018

226 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/4/2019 ASP ADO SQL 2000

    1/51

    [ASP- ADO- ActiveX Data Objects]

    Kolej Komuniti Sabak Bernam | 1

    ASP ADO

    ADO can be used to access databases from your web pages.

    What is ADO?

    ADO is a Microsoft technology ADO stands for ActiveX Data Objects ADO is a Microsoft Active-X component ADO is automatically installed with Microsoft IIS ADO is a programming interface to access data in a database

    Accessing a Database from an ASP Page

    The common way to access a database from inside an ASP page is to:

    1. Create an ADO connection to a database2. Open the database connection3. Create an ADO recordset4. Open the recordset5. Extract the data you need from the recordset6. Close the recordset7. Close the connection

    ADO Database Connection

    Before a database can be accessed from a web page, a database connection has tobe established.

    Create a DSN-less Database Connection

    The easiest way to connect to a database is to use a DSN-less connection. A DSN-less connection canbe used against any Microsoft Access database on your web site.

    If you have a database called "northwind.mdb" located in a web directory like "c:/webdata/", you canconnect to the database with the following ASP code:

  • 8/4/2019 ASP ADO SQL 2000

    2/51

    [ASP- ADO- ActiveX Data Objects]

    Kolej Komuniti Sabak Bernam | 2

    Note, from the example above, that you have to specify the Microsoft Access database driver(Provider) and the physical path to the database on your computer.

    Create an ODBC Database Connection

    If you have an ODBC database called "northwind" you can connect to the database with the followingASP code:

    i. Connection to an MS Access Database:

    With an ODBC connection, you can connect to any database, on any computer in your network, aslong as an ODBC connection is available.

    An ODBC Connection to an MS Access Database

    Here is how to create a connection to a MS Access Database:

    1. Open the ODBC icon in your Control Panel.2. Choose the System DSN tab.3. Click on Add in the System DSN tab.4. Select the Microsoft Access Driver. Click Finish.5.

    In the next screen, click Select to locate the database.6. Give the database a Data Source Name (DSN).

    7. Click OK.

    ii. Connection to an MS SQL Database:

    Note that this configuration has to be done on the computer where your web site is located. If you arerunning Personal Web Server (PWS) or Internet Information Server (IIS) on your own computer, theinstructions above will work, but if your web site is located on a remote server, you have to havephysical access to that server, or ask your web host to do this for you.

  • 8/4/2019 ASP ADO SQL 2000

    3/51

    [ASP- ADO- ActiveX Data Objects]

    Kolej Komuniti Sabak Bernam | 3

    The ADO Connection Object

    The ADO Connection object is used to create an open connection to a data source. Through thisconnection, you can access and manipulate a database.

    ADO RecordsetTo be able to read database data, the data must first be loaded into a recordset.

    Create an ADO Table Recordset

    After an ADO Database Connection has been created, as demonstrated in the previous chapter, it ispossible to create an ADO Recordset.

    Suppose we have a database named "Northwind", we can get access to the "Customers" table inside

    the database with the following lines:

    Create an ADO SQL Recordset

    We can also get access to the data in the "Customers" table using SQL:

  • 8/4/2019 ASP ADO SQL 2000

    4/51

    [ASP- ADO- ActiveX Data Objects]

    Kolej Komuniti Sabak Bernam | 4

    Extract Data from the Recordset

    After a recordset is opened, we can extract data from recordset.

    Suppose we have a database named "Northwind", we can get access to the "Customers" table insidethe database with the following lines:

    Example 1

    The ADO Recordset Object

    The ADO Recordset object is used to hold a set of records from a database table.

    View all methods and properties of the Recordset object.

    ADO Display

    The most common way to display data from a recordset, is to display the data in anHTML table.

    Display the Field Names and Field Values

    We have a database named "Northwind" and we want to display the data from the "Customers" table(remember to save the file with an .asp extension):

    http://www.w3schools.com/ado/ado_ref_recordset.asphttp://www.w3schools.com/ado/ado_ref_recordset.asphttp://www.w3schools.com/ado/ado_ref_recordset.asp
  • 8/4/2019 ASP ADO SQL 2000

    5/51

    [ASP- ADO- ActiveX Data Objects]

    Kolej Komuniti Sabak Bernam | 5

    Example 2

    Display the Field Names and Field Values in an HTML Table

    We can also display the data from the "Customers" table inside an HTML table with the following lines(remember to save the file with an .asp extension):

    Example 3

  • 8/4/2019 ASP ADO SQL 2000

    6/51

    [ASP- ADO- ActiveX Data Objects]

    Kolej Komuniti Sabak Bernam | 6

    set rs = Server.CreateObject("ADODB.recordset")

    rs.Open "SELECT Companyname, Contactname FROM Customers", conn

    %>

    Add Headers to the HTML Table

    We want to add headers to the HTML table to make it more readable (remember to save the file withan .asp extension):

    Example 4

  • 8/4/2019 ASP ADO SQL 2000

    7/51

    [ASP- ADO- ActiveX Data Objects]

    Kolej Komuniti Sabak Bernam | 7

    ADO Queries

    We may use SQL to create queries to specify only a selected set of records andfields to view.

    Display Selected Data

    We want to display only the records from the "Customers" table that have a "Companyname" thatstarts with an A (remember to save the file with an .asp extension):

    Example 5

  • 8/4/2019 ASP ADO SQL 2000

    8/51

    [ASP- ADO- ActiveX Data Objects]

    Kolej Komuniti Sabak Bernam | 8

    WHERE CompanyName LIKE 'A%'"

    rs.Open sql, conn

    %>

    ADO Sort

    We may use SQL to specify how to sort the data in the record set.

    Sort the Data

    We want to display the "Companyname" and "Contactname" fields from the "Customers" table,ordered by "Companyname" (remember to save the file with an .asp extension):

    Example 6

  • 8/4/2019 ASP ADO SQL 2000

    9/51

    [ASP- ADO- ActiveX Data Objects]

    Kolej Komuniti Sabak Bernam | 9

    set rs = Server.CreateObject("ADODB.recordset")

    sql="SELECT Companyname, Contactname FROM

    Customers ORDER BY CompanyName"

    rs.Open sql, conn

    %>

    ADO Add Records

    We may use the SQL INSERT INTO command to add a record to a table in adatabase.

    Add a Record to a Table in a Database

    We want to add a new record to the Customers table in the Northwind database. We first create a

    form that contains the fields we want to collect data from:

    Example 7 - Form

  • 8/4/2019 ASP ADO SQL 2000

    10/51

    [ASP- ADO- ActiveX Data Objects]

    Kolej Komuniti Sabak Bernam | 10

    CustomerID:

    Company Name:

    Contact Name:

    Address:

    City:

    Postal Code:

    Country:



    When the user presses the submit button the form is sent to a file called "form_add.asp". The"form_add.asp" file contains the code that will add a new record to the Customers table:

    Example 7 Form Add

  • 8/4/2019 ASP ADO SQL 2000

    11/51

    [ASP- ADO- ActiveX Data Objects]

    Kolej Komuniti Sabak Bernam | 11

    sql=sql & "contactname,address,city,postalcode,country)"

    sql=sql & " VALUES "

    sql=sql & "('" & Request.Form("custid") & "',"

    sql=sql & "'" & Request.Form("compname") & "',"

    sql=sql & "'" & Request.Form("contname") & "',"

    sql=sql & "'" & Request.Form("address") & "',"sql=sql & "'" & Request.Form("city") & "',"

    sql=sql & "'" & Request.Form("postcode") & "',"

    sql=sql & "'" & Request.Form("country") & "')"

    on error resume next

    conn.Execute sql,recaffected

    if err0 then

    Response.Write("No update permissions!")

    else

    Response.Write("" & recaffected & " record added")

    end if

    conn.close%>

    Important

    If you use the SQL INSERT command be aware of the following:

    If the table contains a primary key, make sure to append a unique, non-Null value to theprimary key field (if not, the provider may not append the record, or an error occurs)

    If the table contains an AutoNumber field, do not include this field in the SQL INSERTcommand (the value of this field will be taken care of automatically by the provider)

    What about Fields With no Data?

    In a MS Access database, you can enter zero-length strings ("") in Text, Hyperlink, and Memo fields IFyou set the AllowZeroLength property to Yes.

    Note: Not all databases support zero-length strings and may cause an error when a record with blankfields is added. It is important to check what data types your database supports.

    ADO Update Records

    We may use the SQL UPDATE command to update a record in a table in adatabase.

  • 8/4/2019 ASP ADO SQL 2000

    12/51

    [ASP- ADO- ActiveX Data Objects]

    Kolej Komuniti Sabak Bernam | 12

    Update a Record in a Table

    We want to update a record in the Customers table in the Northwind database. We first create a tablethat lists all records in the Customers table:

    Example 8 Form

    List Database

  • 8/4/2019 ASP ADO SQL 2000

    13/51

    [ASP- ADO- ActiveX Data Objects]

    Kolej Komuniti Sabak Bernam | 13

    If the user clicks on the button in the "customerID" column he or she will be taken to a new file called"form_update.asp". The "form_update.asp" file contains the source code on how to create input fields

    based on the fields from one record in the database table. It also contains a "Update record" buttonthat will save your changes: :

    Example 8 Form Update

    Update Record



  • 8/4/2019 ASP ADO SQL 2000

    14/51

    [ASP- ADO- ActiveX Data Objects]

    Kolej Komuniti Sabak Bernam | 14

    sql=sql & "address='" & Request.Form("address") & "',"

    sql=sql & "city='" & Request.Form("city") & "',"

    sql=sql & "Region='" & Request.Form("Region") & "',"

    sql=sql & "postalcode='" & Request.Form("postalcode") & "',"

    sql=sql & "country='" & Request.Form("country") & "',"

    sql=sql & "Phone='" & Request.Form("Phone") & "',"

    sql=sql & "Fax='" & Request.Form("Fax") & "'"

    sql=sql & " WHERE customerID='" & cid & "'"

    on error resume next

    conn.Execute sql

    if err0 then

    response.write("No update permissions!")

    else

    response.write("Record " & cid & " was updated!")

    end if

    end if

    conn.close%>

    ADO Delete Records

    We may use the SQL DELETE command to delete a record in a table in a database.

    Delete a Record in a Table

    We want to delete a record in the Customers table in the Northwind database. We first create a tablethat lists all records in the Customers table: :

    Example 9 - Form

  • 8/4/2019 ASP ADO SQL 2000

    15/51

    [ASP- ADO- ActiveX Data Objects]

    Kolej Komuniti Sabak Bernam | 15

    %>

    List Database

    If the user clicks on the button in the "customerID" column he or she will be taken to a new file called

    "form_delete.asp". The "form_delete.asp" file contains the source code on how to create input fieldsbased on the fields from one record in the database table. It also contains a "Delete record" buttonthat will delete the current record: :

    Example 9 Form Delete

  • 8/4/2019 ASP ADO SQL 2000

    16/51

    [ASP- ADO- ActiveX Data Objects]

    Kolej Komuniti Sabak Bernam | 16

    Delete Record



    ADO Demonstration

  • 8/4/2019 ASP ADO SQL 2000

    17/51

    [ASP- ADO- ActiveX Data Objects]

    Kolej Komuniti Sabak Bernam | 17

    To demonstrate a small real life ADO application, we have put together a few ADOdemos.

    Read this First

    If you try to update the database, you will get the error message: "You do not have permission toupdate this database". You get this error because you don't have write access to our server.

    BUT, if you copy the code and run it on your own system, you might get the same error. That isbecause the system might see you as an anonymous internet user when you access the file via yourbrowser. In that case, you have to change the access-rights to get access to the file.

    How to change the access-rights of your Access database?

    Open Windows Explorer, find the .mdb file. Right-click on the .mdb file and select Properties. Go to theSecurity tab and set the access-rights here.

    List, Edit, Update, and Delete Database Records

    List, edit, update, and delete database records

    Add a New Record to a Database

    Add a new record

    ADO Speed Up With GetString()

    Use the GetString() method to speed up your ASP script (instead of using multipleResponse.Write's).

    Multiple Response.Write's

    The following example demonstrates one way of how to display a database query in an HTML table: :

    Example 10

    http://www.w3schools.com/ado/demo_db_list.asphttp://www.w3schools.com/ado/demo_db_list.asphttp://www.w3schools.com/ado/demo_db_add.asphttp://www.w3schools.com/ado/demo_db_add.asphttp://www.w3schools.com/ado/demo_db_add.asphttp://www.w3schools.com/ado/demo_db_list.asp
  • 8/4/2019 ASP ADO SQL 2000

    18/51

    [ASP- ADO- ActiveX Data Objects]

    Kolej Komuniti Sabak Bernam | 18

    For a large query, this can slow down the script processing time, since many Response.Writecommands must be processed by the server.

    The solution is to have the entire string created, from to , and then output it - usingResponse.Write just once.

    The GetString() Method

    The GetString() method allows you to display the string with only one Response.Write. It alsoeliminates the do...loop code and the conditional test that checks if the recordset is at EOF.

    Syntax

    str = rs.GetString(format,rows,coldel,rowdel,nullexpr)

  • 8/4/2019 ASP ADO SQL 2000

    19/51

    [ASP- ADO- ActiveX Data Objects]

    Kolej Komuniti Sabak Bernam | 19

    To create an HTML table with data from a recordset, we only need to use three of the parametersabove (all parameters are optional):

    coldel - the HTML to use as a column-separator rowdel - the HTML to use as a row-separator nullexpr - the HTML to use if a column is NULL

    Note: The GetString() method is an ADO 2.0 feature. You can download ADO 2.0 athttp://www.microsoft.com/data/download.htm.

    In the following example we will use the GetString() method to hold the recordset as a string:

    Example 11

    The str variable above contains a string of all the columns and rows returned by the SQL SELECTstatement. Between each column the HTML will appear, and between each row, the HTML will appear. This will produce the exact HTML we need with only oneResponse.Write.

    ADO Command Object

    http://www.microsoft.com/data/download.htmhttp://www.microsoft.com/data/download.htmhttp://www.microsoft.com/data/download.htm
  • 8/4/2019 ASP ADO SQL 2000

    20/51

    [ASP- ADO- ActiveX Data Objects]

    Kolej Komuniti Sabak Bernam | 20

    Command Object

    The ADO Command object is used to execute a single query against a database. The query canperform actions like creating, adding, retrieving, deleting or updating records.

    If the query is used to retrieve data, the data will be returned as a RecordSet object. This means that

    the retrieved data can be manipulated by properties, collections, methods, and events of theRecordset object.

    The major feature of the Command object is the ability to use stored queries and procedures withparameters.

    ProgID

    set objCommand=Server.CreateObject("ADODB.command")

    Properties

    Property Description

    ActiveConnection Sets or returns a definition for a connection if the connection is closed,

    or the current Connection object if the connection is open

    CommandText Sets or returns a provider command

    CommandTimeout Sets or returns the number of seconds to wait while attempting to

    execute a command

    CommandType Sets or returns the type of a Command object

    Name Sets or returns the name of a Command object

    Prepared Sets or returns a Boolean value that, if set to True, indicates that the

    command should save a prepared version of the query before the first

    execution

    State Returns a value that describes if the Command object is open, closed,

    connecting, executing or retrieving data

    Methods

    Method Description

    Cancel Cancels an execution of a method

    http://www.w3schools.com/ado/prop_comm_activeconn.asphttp://www.w3schools.com/ado/prop_comm_commandtext.asphttp://www.w3schools.com/ado/prop_comm_commandtext.asphttp://www.w3schools.com/ado/prop_commandtimeout.asphttp://www.w3schools.com/ado/prop_comm_commandtype.asphttp://www.w3schools.com/ado/prop_comm_commandtype.asphttp://www.w3schools.com/ado/prop_comm_name.asphttp://www.w3schools.com/ado/prop_comm_name.asphttp://www.w3schools.com/ado/prop_comm_prepared.asphttp://www.w3schools.com/ado/prop_comm_state.asphttp://www.w3schools.com/ado/met_comm_cancel.asphttp://www.w3schools.com/ado/met_comm_cancel.asphttp://www.w3schools.com/ado/met_comm_cancel.asphttp://www.w3schools.com/ado/prop_comm_state.asphttp://www.w3schools.com/ado/prop_comm_prepared.asphttp://www.w3schools.com/ado/prop_comm_name.asphttp://www.w3schools.com/ado/prop_comm_commandtype.asphttp://www.w3schools.com/ado/prop_commandtimeout.asphttp://www.w3schools.com/ado/prop_comm_commandtext.asphttp://www.w3schools.com/ado/prop_comm_activeconn.asp
  • 8/4/2019 ASP ADO SQL 2000

    21/51

    [ASP- ADO- ActiveX Data Objects]

    Kolej Komuniti Sabak Bernam | 21

    CreateParameter Creates a new Parameter object

    Execute Executes the query, SQL statement or procedure in the CommandText

    property

    Collections

    Collection Description

    Parameters Contains all the Parameter objects of a Command Object

    Properties Contains all the Property objects of a Command Object

    ADO Connection Object

    Connection Object

    The ADO Connection Object is used to create an open connection to a data source. Through thisconnection, you can access and manipulate a database.

    If you want to access a database multiple times, you should establish a connection using theConnection object. You can also make a connection to a database by passing a connection string via aCommand or Recordset object. However, this type of connection is only good for one specific, singlequery.

    ProgID

    set objConnection=Server.CreateObject("ADODB.connection")

    Properties

    Property Description

    Attributes Sets or returns the attributes of a Connection object

    CommandTimeout Sets or returns the number of seconds to wait while attempting to

    execute a command

    ConnectionString Sets or returns the details used to create a connection to a data source

    ConnectionTimeout Sets or returns the number of seconds to wait for a connection to open

    http://www.w3schools.com/ado/met_comm_createparameter.asphttp://www.w3schools.com/ado/met_comm_execute.asphttp://www.w3schools.com/ado/met_comm_execute.asphttp://www.w3schools.com/ado/prop_conn_attributes.asphttp://www.w3schools.com/ado/prop_conn_commandtimeout.asphttp://www.w3schools.com/ado/prop_conn_connectionstring.asphttp://www.w3schools.com/ado/prop_conn_connectiontimeout.asphttp://www.w3schools.com/ado/prop_conn_connectiontimeout.asphttp://www.w3schools.com/ado/prop_conn_connectiontimeout.asphttp://www.w3schools.com/ado/prop_conn_connectionstring.asphttp://www.w3schools.com/ado/prop_conn_commandtimeout.asphttp://www.w3schools.com/ado/prop_conn_attributes.asphttp://www.w3schools.com/ado/met_comm_execute.asphttp://www.w3schools.com/ado/met_comm_createparameter.asp
  • 8/4/2019 ASP ADO SQL 2000

    22/51

    [ASP- ADO- ActiveX Data Objects]

    Kolej Komuniti Sabak Bernam | 22

    CursorLocation Sets or returns the location of the cursor service

    DefaultDatabase Sets or returns the default database name

    IsolationLevel Sets or returns the isolation level

    Mode Sets or returns the provider access permission

    Provider Sets or returns the provider name

    State Returns a value describing if the connection is open or closed

    Version Returns the ADO version number

    Methods

    Method Description

    BeginTrans Begins a new transaction

    Cancel Cancels an execution

    Close Closes a connection

    CommitTrans Saves any changes and ends the current transaction

    Execute Executes a query, statement, procedure or provider specific text

    Open Opens a connection

    OpenSchema Returns schema information from the provider about the data source

    RollbackTrans Cancels any changes in the current transaction and ends the

    transaction

    Events

    Note: You cannot handle events using VBScript or JScript (only Visual Basic, Visual C++, and Visual

    J++ languages can handle events).

    Event Description

    BeginTransComplete Triggered after the BeginTrans operation

    CommitTransComplete Triggered after the CommitTrans operation

    http://www.w3schools.com/ado/prop_conn_cursorlocation.asphttp://www.w3schools.com/ado/prop_conn_defaultdb.asphttp://www.w3schools.com/ado/prop_conn_isolationlevel.asphttp://www.w3schools.com/ado/prop_conn_mode.asphttp://www.w3schools.com/ado/prop_conn_provider.asphttp://www.w3schools.com/ado/prop_conn_state.asphttp://www.w3schools.com/ado/prop_conn_version.asphttp://www.w3schools.com/ado/met_conn_begintrans.asphttp://www.w3schools.com/ado/met_conn_begintrans.asphttp://www.w3schools.com/ado/met_conn_cancel.asphttp://www.w3schools.com/ado/met_conn_cancel.asphttp://www.w3schools.com/ado/met_conn_close.asphttp://www.w3schools.com/ado/met_conn_begintrans.asphttp://www.w3schools.com/ado/met_conn_begintrans.asphttp://www.w3schools.com/ado/met_conn_execute.asphttp://www.w3schools.com/ado/met_conn_execute.asphttp://www.w3schools.com/ado/met_conn_open.asphttp://www.w3schools.com/ado/met_conn_openschema.asphttp://www.w3schools.com/ado/met_conn_openschema.asphttp://www.w3schools.com/ado/met_conn_begintrans.asphttp://www.w3schools.com/ado/met_conn_begintrans.asphttp://www.w3schools.com/ado/ev_conn_transcomplete.asphttp://www.w3schools.com/ado/ev_conn_transcomplete.asphttp://www.w3schools.com/ado/ev_conn_transcomplete.asphttp://www.w3schools.com/ado/ev_conn_transcomplete.asphttp://www.w3schools.com/ado/met_conn_begintrans.asphttp://www.w3schools.com/ado/met_conn_openschema.asphttp://www.w3schools.com/ado/met_conn_open.asphttp://www.w3schools.com/ado/met_conn_execute.asphttp://www.w3schools.com/ado/met_conn_begintrans.asphttp://www.w3schools.com/ado/met_conn_close.asphttp://www.w3schools.com/ado/met_conn_cancel.asphttp://www.w3schools.com/ado/met_conn_begintrans.asphttp://www.w3schools.com/ado/prop_conn_version.asphttp://www.w3schools.com/ado/prop_conn_state.asphttp://www.w3schools.com/ado/prop_conn_provider.asphttp://www.w3schools.com/ado/prop_conn_mode.asphttp://www.w3schools.com/ado/prop_conn_isolationlevel.asphttp://www.w3schools.com/ado/prop_conn_defaultdb.asphttp://www.w3schools.com/ado/prop_conn_cursorlocation.asp
  • 8/4/2019 ASP ADO SQL 2000

    23/51

    [ASP- ADO- ActiveX Data Objects]

    Kolej Komuniti Sabak Bernam | 23

    ConnectComplete Triggered after a connection starts

    Disconnect Triggered after a connection ends

    ExecuteComplete Triggered after a command has finished executing

    InfoMessage Triggered if a warning occurs during a ConnectionEvent operation

    RollbackTransComplete Triggered after the RollbackTrans operation

    WillConnect Triggered before a connection starts

    WillExecute Triggered before a command is executed

    Collections

    Collection Description

    Errors Contains all the Error objects of the Connection object

    Properties Contains all the Property objects of the Connection object

    ADO Error Object

    Error Object

    The ADO Error object contains details about data access errors that have been generated during asingle operation.

    ADO generates one Error object for each error. Each Error object contains details of the specific error,and are stored in the Errors collection. To access the errors, you must refer to a specific connection.

    To loop through the Errors collection:

  • 8/4/2019 ASP ADO SQL 2000

    24/51

    [ASP- ADO- ActiveX Data Objects]

    Kolej Komuniti Sabak Bernam | 24

    response.write(objErr.NativeError & "
    ")

    response.write("Error number: ")

    response.write(objErr.Number & "
    ")

    response.write("Error source: ")

    response.write(objErr.Source & "
    ")

    response.write("SQL state: ")response.write(objErr.SQLState & "
    ")

    response.write("

    ")

    next

    %>

    Syntax

    objErr.property

    Properties

    Property Description

    Description Returns an error description

    HelpContext Returns the context ID of a topic in the Microsoft Windows help system

    HelpFile Returns the full path of the help file in the Microsoft Windows help

    system

    NativeError Returns an error code from the provider or the data source

    Number Returns a unique number that identifies the error

    Source Returns the name of the object or application that generated the error

    SQLState Returns a 5-character SQL error code

    ADO Field Object

    Field Object

    The ADO Field object contains information about a column in a Recordset object. There is one Fieldobject for each column in the Recordset.

    http://www.w3schools.com/ado/prop_err_description.asphttp://www.w3schools.com/ado/prop_err_helpcontext.asphttp://www.w3schools.com/ado/prop_err_helpfile.asphttp://www.w3schools.com/ado/prop_err_nativeerror.asphttp://www.w3schools.com/ado/prop_err_number.asphttp://www.w3schools.com/ado/prop_err_number.asphttp://www.w3schools.com/ado/prop_err_source.asphttp://www.w3schools.com/ado/prop_err_source.asphttp://www.w3schools.com/ado/prop_err_sqlstate.asphttp://www.w3schools.com/ado/prop_err_sqlstate.asphttp://www.w3schools.com/ado/prop_err_source.asphttp://www.w3schools.com/ado/prop_err_number.asphttp://www.w3schools.com/ado/prop_err_nativeerror.asphttp://www.w3schools.com/ado/prop_err_helpfile.asphttp://www.w3schools.com/ado/prop_err_helpcontext.asphttp://www.w3schools.com/ado/prop_err_description.asp
  • 8/4/2019 ASP ADO SQL 2000

    25/51

    [ASP- ADO- ActiveX Data Objects]

    Kolej Komuniti Sabak Bernam | 25

    ProgID

    set objField=Server.CreateObject("ADODB.field")

    Properties

    Property Description

    ActualSize Returns the actual length of a field's value

    Attributes Sets or returns the attributes of a Field object

    DefinedSize Returns the defined size of a field

    Name Sets or returns the name of a Field object

    NumericScale Sets or returns the number of decimal places allowed for numeric

    values in a Field object

    OriginalValue Returns the original value of a field

    Precision Sets or returns the maximum number of digits allowed when

    representing numeric values in a Field object

    Status Returns the status of a Field object

    Type Sets or returns the type of a Field object

    UnderlyingValue Returns the current value of a field

    Value Sets or returns the value of a Field object

    Methods

    Method Description

    AppendChunk

    Appends long binary or character data to a Field object

    GetChunk Returns all or a part of the contents of a large text or binary data Field

    object

    http://www.w3schools.com/ado/prop_field_size.asphttp://www.w3schools.com/ado/prop_field_size.asphttp://www.w3schools.com/ado/prop_field_attributes.asphttp://www.w3schools.com/ado/prop_field_size.asphttp://www.w3schools.com/ado/prop_field_name.asphttp://www.w3schools.com/ado/prop_field_name.asphttp://www.w3schools.com/ado/prop_field_numericscale.asphttp://www.w3schools.com/ado/prop_field_numericscale.asphttp://www.w3schools.com/ado/prop_field_originalvalue_underlyingvalue.asphttp://www.w3schools.com/ado/prop_field_precision.asphttp://www.w3schools.com/ado/prop_field_status.asphttp://www.w3schools.com/ado/prop_field_type.asphttp://www.w3schools.com/ado/prop_field_type.asphttp://www.w3schools.com/ado/prop_field_originalvalue_underlyingvalue.asphttp://www.w3schools.com/ado/prop_field_originalvalue_underlyingvalue.asphttp://www.w3schools.com/ado/prop_field_value.asphttp://www.w3schools.com/ado/prop_field_value.asphttp://www.w3schools.com/ado/met_field_appendchunk.asphttp://www.w3schools.com/ado/met_field_appendchunk.asphttp://www.w3schools.com/ado/met_field_getchunk.asphttp://www.w3schools.com/ado/met_field_getchunk.asphttp://www.w3schools.com/ado/met_field_getchunk.asphttp://www.w3schools.com/ado/met_field_appendchunk.asphttp://www.w3schools.com/ado/prop_field_value.asphttp://www.w3schools.com/ado/prop_field_originalvalue_underlyingvalue.asphttp://www.w3schools.com/ado/prop_field_type.asphttp://www.w3schools.com/ado/prop_field_status.asphttp://www.w3schools.com/ado/prop_field_precision.asphttp://www.w3schools.com/ado/prop_field_originalvalue_underlyingvalue.asphttp://www.w3schools.com/ado/prop_field_numericscale.asphttp://www.w3schools.com/ado/prop_field_name.asphttp://www.w3schools.com/ado/prop_field_size.asphttp://www.w3schools.com/ado/prop_field_attributes.asphttp://www.w3schools.com/ado/prop_field_size.asp
  • 8/4/2019 ASP ADO SQL 2000

    26/51

    [ASP- ADO- ActiveX Data Objects]

    Kolej Komuniti Sabak Bernam | 26

    Collections

    Collection Description

    Properties Contains all the Property objects for a Field object

    ADO Parameter Object

    Parameter Object

    The ADO Parameter object provides information about a single parameter used in a stored procedureor query.

    A Parameter object is added to the Parameters Collection when it is created. The ParametersCollection is associated with a specific Command object, which uses the Collection to pass parametersin and out of stored procedures and queries.

    Parameters can be used to create Parameterized Commands. These commands are (after they havebeen defined and stored) using parameters to alter some details of the command before it isexecuted. For example, an SQL SELECT statement could use a parameter to define the criteria of aWHERE clause.

    There are four types of parameters: input parameters, output parameters, input/output parametersand return parameters.

    Syntax

    objectname.property

    objectname.method

    Properties

    Property Description

    Attributes Sets or returns the attributes of a Parameter object

    Direction Sets or returns how a parameter is passed to or from a procedure

    Name Sets or returns the name of a Parameter object

    NumericScale Sets or returns the number of digits stored to the right side of the

    decimal point for a numeric value of a Parameter object

    Precision Sets or returns the maximum number of digits allowed when

    representing numeric values in a Parameter

    http://www.w3schools.com/ado/prop_para_attributes.asphttp://www.w3schools.com/ado/prop_para_direction.asphttp://www.w3schools.com/ado/prop_para_name.asphttp://www.w3schools.com/ado/prop_para_name.asphttp://www.w3schools.com/ado/prop_para_numericscale.asphttp://www.w3schools.com/ado/prop_para_numericscale.asphttp://www.w3schools.com/ado/prop_para_precision.asphttp://www.w3schools.com/ado/prop_para_precision.asphttp://www.w3schools.com/ado/prop_para_numericscale.asphttp://www.w3schools.com/ado/prop_para_name.asphttp://www.w3schools.com/ado/prop_para_direction.asphttp://www.w3schools.com/ado/prop_para_attributes.asp
  • 8/4/2019 ASP ADO SQL 2000

    27/51

  • 8/4/2019 ASP ADO SQL 2000

    28/51

    [ASP- ADO- ActiveX Data Objects]

    Kolej Komuniti Sabak Bernam | 28

    Value Sets or returns the value of a Property object

    ADO Record Object

    Record Object (ADO version 2.5)

    The ADO Record object is used to hold a row in a Recordset, a directory, or a file from a file system.

    Only structured databases could be accessed by ADO in versions prior 2.5. In a structured database,

    each table has the exact same number of columns in each row, and each column is composed of thesame data type.

    The Record object allows access to data-sets where the number of columns and/or the data type canbe different from row to row.

    Syntax

    objectname.property

    objectname.method

    Properties

    Property Description

    ActiveConnection Sets or returns which Connection object a Record object belongs

    to

    Mode Sets or returns the permission for modifying data in a Record

    object

    ParentURL Returns the absolute URL of the parent Record

    RecordType Returns the type of a Record object

    Source Sets or returns the src parameter of the Open method of a Record

    object

    State Returns the status of a Record object

    Methods

    Method Description

    Cancel Cancels an execution of a CopyRecord, DeleteRecord,

    http://www.w3schools.com/ado/prop_prop_value.asphttp://www.w3schools.com/ado/prop_prop_value.asphttp://www.w3schools.com/ado/prop_rec_activeconn.asphttp://www.w3schools.com/ado/prop_rec_mode.asphttp://www.w3schools.com/ado/prop_rec_parenturl.asphttp://www.w3schools.com/ado/prop_rec_parenturl.asphttp://www.w3schools.com/ado/prop_rec_recordtype.asphttp://www.w3schools.com/ado/prop_rec_source.asphttp://www.w3schools.com/ado/prop_rec_source.asphttp://www.w3schools.com/ado/prop_rec_state.asphttp://www.w3schools.com/ado/met_rec_cancel.asphttp://www.w3schools.com/ado/met_rec_cancel.asphttp://www.w3schools.com/ado/met_rec_cancel.asphttp://www.w3schools.com/ado/prop_rec_state.asphttp://www.w3schools.com/ado/prop_rec_source.asphttp://www.w3schools.com/ado/prop_rec_recordtype.asphttp://www.w3schools.com/ado/prop_rec_parenturl.asphttp://www.w3schools.com/ado/prop_rec_mode.asphttp://www.w3schools.com/ado/prop_rec_activeconn.asphttp://www.w3schools.com/ado/prop_prop_value.asp
  • 8/4/2019 ASP ADO SQL 2000

    29/51

    [ASP- ADO- ActiveX Data Objects]

    Kolej Komuniti Sabak Bernam | 29

    MoveRecord, or Open call

    Close Closes a Record object

    CopyRecord Copies a file or directory to another location

    DeleteRecord Deletes a file or directory

    GetChildren Returns a Recordset object where each row represents the files in

    the directory

    MoveRecord Moves a file or a directory to another location

    Open Opens an existing Record object or creates a new file or directory

    Collections

    Collection Description

    Properties A collection of provider-specific properties

    Fields Contains all the Field objects in the Record object

    The Fields Collection's Properties

    Property Description

    Count Returns the number of items in the fields collection. Starts at

    zero.

    Example:

    countfields=rec.Fields.Count

    Item(named_item/number) Returns a specified item in the fields collection.

    Example:

    itemfields=rec.Fields.Item(1)oritemfields = rec.Fields.Item("Name")

    ADO Recordset Object

    Recordset Object

    http://www.w3schools.com/ado/met_rec_close.asphttp://www.w3schools.com/ado/met_rec_copy_move_record.asphttp://www.w3schools.com/ado/met_rec_deleterecord.asphttp://www.w3schools.com/ado/met_rec_getchildren.asphttp://www.w3schools.com/ado/met_rec_copy_move_record.asphttp://www.w3schools.com/ado/met_rec_open.asphttp://www.w3schools.com/ado/met_rec_open.asphttp://www.w3schools.com/ado/met_rec_copy_move_record.asphttp://www.w3schools.com/ado/met_rec_getchildren.asphttp://www.w3schools.com/ado/met_rec_deleterecord.asphttp://www.w3schools.com/ado/met_rec_copy_move_record.asphttp://www.w3schools.com/ado/met_rec_close.asp
  • 8/4/2019 ASP ADO SQL 2000

    30/51

    [ASP- ADO- ActiveX Data Objects]

    Kolej Komuniti Sabak Bernam | 30

    The ADO Recordset object is used to hold a set of records from a database table. A Recordset objectconsist of records and columns (fields).

    In ADO, this object is the most important and the one used most often to manipulate data from adatabase.

    ProgID

    set objRecordset=Server.CreateObject("ADODB.recordset")

    When you first open a Recordset, the current record pointer will point to the first record and the BOF

    and EOF properties are False. If there are no records, the BOF and EOF property are True.

    Recordset objects can support two types of updating:

    Immediate updating - all changes are written immediately to the database once you call theUpdate method.

    Batch updating - the provider will cache multiple changes and then send them to thedatabase with the UpdateBatch method.In ADO there are 4 different cursor types defined:

    Dynamic cursor - Allows you to see additions, changes, and deletions by other users. Keyset cursor - Like a dynamic cursor, except that you cannot see additions by other users,

    and it prevents access to records that other users have deleted. Data changes by other userswill still be visible.

    Static cursor - Provides a static copy of a recordset for you to use to find data or generatereports. Additions, changes, or deletions by other users will not be visible. This is the only typeof cursor allowed when you open a client-side Recordset object.

    Forward-only cursor - Allows you to only scroll forward through the Recordset. Additions,changes, or deletions by other users will not be visible.

    The cursor type can be set by the CursorType property or by the CursorType parameter in the Openmethod.

    Note: Not all providers support all methods or properties of the Recordset object.

    Properties

    Property Description

    AbsolutePage Sets or returns a value that specifies the page number in theRecordset object

    AbsolutePosition Sets or returns a value that specifies the ordinal position of the

    current record in the Recordset object

    ActiveCommand Returns the Command object associated with the Recordset

    http://www.w3schools.com/ado/prop_rs_absolute.asphttp://www.w3schools.com/ado/prop_rs_absolute.asphttp://www.w3schools.com/ado/prop_rs_active.asphttp://www.w3schools.com/ado/prop_rs_active.asphttp://www.w3schools.com/ado/prop_rs_active.asphttp://www.w3schools.com/ado/prop_rs_absolute.asphttp://www.w3schools.com/ado/prop_rs_absolute.asp
  • 8/4/2019 ASP ADO SQL 2000

    31/51

    [ASP- ADO- ActiveX Data Objects]

    Kolej Komuniti Sabak Bernam | 31

    ActiveConnection Sets or returns a definition for a connection if the connection is

    closed, or the current Connection object if the connection is open

    BOF Returns true if the current record position is before the first

    record, otherwise false

    Bookmark Sets or returns a bookmark. The bookmark saves the position of

    the current record

    CacheSize Sets or returns the number of records that can be cached

    CursorLocation Sets or returns the location of the cursor service

    CursorType Sets or returns the cursor type of a Recordset object

    DataMember Sets or returns the name of the data member that will be

    retrieved from the object referenced by the DataSource property

    DataSource Specifies an object containing data to be represented as a

    Recordset object

    EditMode Returns the editing status of the current record

    EOF Returns true if the current record position is after the last record,

    otherwise false

    Filter Sets or returns a filter for the data in a Recordset object

    Index Sets or returns the name of the current index for a Recordset

    object

    LockType Sets or returns a value that specifies the type of locking when

    editing a record in a Recordset

    MarshalOptions Sets or returns a value that specifies which records are to be

    returned to the server

    MaxRecords Sets or returns the maximum number of records to return to a

    Recordset object from a query

    PageCount Returns the number of pages with data in a Recordset object

    PageSize Sets or returns the maximum number of records allowed on a

    single page of a Recordset object

    RecordCount Returns the number of records in a Recordset object

    http://www.w3schools.com/ado/prop_rs_active.asphttp://www.w3schools.com/ado/prop_rs_bofeof.asphttp://www.w3schools.com/ado/prop_rs_bofeof.asphttp://www.w3schools.com/ado/prop_rs_bookmark.asphttp://www.w3schools.com/ado/prop_rs_cachesize.asphttp://www.w3schools.com/ado/prop_rs_cachesize.asphttp://www.w3schools.com/ado/prop_rs_cursorlocation.asphttp://www.w3schools.com/ado/prop_rs_cursortype.asphttp://www.w3schools.com/ado/prop_rs_cursortype.asphttp://www.w3schools.com/ado/prop_rs_datamember.asphttp://www.w3schools.com/ado/prop_rs_datasource.asphttp://www.w3schools.com/ado/prop_rs_editmode.asphttp://www.w3schools.com/ado/prop_rs_bofeof.asphttp://www.w3schools.com/ado/prop_rs_bofeof.asphttp://www.w3schools.com/ado/prop_rs_filter.asphttp://www.w3schools.com/ado/prop_rs_index.asphttp://www.w3schools.com/ado/prop_rs_index.asphttp://www.w3schools.com/ado/prop_rs_locktype.asphttp://www.w3schools.com/ado/prop_rs_locktype.asphttp://www.w3schools.com/ado/prop_rs_marshaloptions.asphttp://www.w3schools.com/ado/prop_rs_maxrecords.asphttp://www.w3schools.com/ado/prop_rs_pagecount.asphttp://www.w3schools.com/ado/prop_rs_pagecount.asphttp://www.w3schools.com/ado/prop_rs_pagesize.asphttp://www.w3schools.com/ado/prop_rs_pagesize.asphttp://www.w3schools.com/ado/prop_rs_recordcount.asphttp://www.w3schools.com/ado/prop_rs_recordcount.asphttp://www.w3schools.com/ado/prop_rs_recordcount.asphttp://www.w3schools.com/ado/prop_rs_pagesize.asphttp://www.w3schools.com/ado/prop_rs_pagecount.asphttp://www.w3schools.com/ado/prop_rs_maxrecords.asphttp://www.w3schools.com/ado/prop_rs_marshaloptions.asphttp://www.w3schools.com/ado/prop_rs_locktype.asphttp://www.w3schools.com/ado/prop_rs_index.asphttp://www.w3schools.com/ado/prop_rs_filter.asphttp://www.w3schools.com/ado/prop_rs_bofeof.asphttp://www.w3schools.com/ado/prop_rs_editmode.asphttp://www.w3schools.com/ado/prop_rs_datasource.asphttp://www.w3schools.com/ado/prop_rs_datamember.asphttp://www.w3schools.com/ado/prop_rs_cursortype.asphttp://www.w3schools.com/ado/prop_rs_cursorlocation.asphttp://www.w3schools.com/ado/prop_rs_cachesize.asphttp://www.w3schools.com/ado/prop_rs_bookmark.asphttp://www.w3schools.com/ado/prop_rs_bofeof.asphttp://www.w3schools.com/ado/prop_rs_active.asp
  • 8/4/2019 ASP ADO SQL 2000

    32/51

    [ASP- ADO- ActiveX Data Objects]

    Kolej Komuniti Sabak Bernam | 32

    Sort Sets or returns the field names in the Recordset to sort on

    Source Sets a string value or a Command object reference, or returns a

    String value that indicates the data source of the Recordset object

    State Returns a value that describes if the Recordset object is open,closed, connecting, executing or retrieving data

    Status Returns the status of the current record with regard to batch

    updates or other bulk operations

    StayInSync Sets or returns whether the reference to the child records will

    change when the parent record position changes

    Methods

    Method Description

    AddNew Creates a new record

    Cancel Cancels an execution

    CancelBatch Cancels a batch update

    CancelUpdate Cancels changes made to a record of a Recordset object

    Clone Creates a duplicate of an existing Recordset

    Close Closes a Recordset

    CompareBookmarks Compares two bookmarks

    Delete Deletes a record or a group of records

    Find Searches for a record in a Recordset that satisfies a specified

    criteria

    GetRows Copies multiple records from a Recordset object into a two-

    dimensional array

    GetString Returns a Recordset as a string

    Move Moves the record pointer in a Recordset object

    MoveFirst Moves the record pointer to the first record

    http://www.w3schools.com/ado/prop_rs_sort.asphttp://www.w3schools.com/ado/prop_rs_source.asphttp://www.w3schools.com/ado/prop_rs_source.asphttp://www.w3schools.com/ado/prop_rs_state.asphttp://www.w3schools.com/ado/prop_rs_status.asphttp://www.w3schools.com/ado/prop_rs_stayinsync.asphttp://www.w3schools.com/ado/prop_rs_stayinsync.asphttp://www.w3schools.com/ado/met_rs_addnew.asphttp://www.w3schools.com/ado/met_rs_cancel.asphttp://www.w3schools.com/ado/met_rs_cancel.asphttp://www.w3schools.com/ado/met_rs_cancelbatch.asphttp://www.w3schools.com/ado/met_rs_cancelbatch.asphttp://www.w3schools.com/ado/met_rs_cancelupdate.asphttp://www.w3schools.com/ado/met_rs_clone.asphttp://www.w3schools.com/ado/met_rs_clone.asphttp://www.w3schools.com/ado/met_rs_close.asphttp://www.w3schools.com/ado/met_rs_comparebookmarks.asphttp://www.w3schools.com/ado/met_rs_comparebookmarks.asphttp://www.w3schools.com/ado/met_rs_delete.asphttp://www.w3schools.com/ado/met_rs_find.asphttp://www.w3schools.com/ado/met_rs_find.asphttp://www.w3schools.com/ado/met_rs_getrows.asphttp://www.w3schools.com/ado/met_rs_getrows.asphttp://www.w3schools.com/ado/met_rs_getstring.asphttp://www.w3schools.com/ado/met_rs_move.asphttp://www.w3schools.com/ado/met_rs_move.asphttp://www.w3schools.com/ado/met_rs_movefirst.asphttp://www.w3schools.com/ado/met_rs_movefirst.asphttp://www.w3schools.com/ado/met_rs_move.asphttp://www.w3schools.com/ado/met_rs_getstring.asphttp://www.w3schools.com/ado/met_rs_getrows.asphttp://www.w3schools.com/ado/met_rs_find.asphttp://www.w3schools.com/ado/met_rs_delete.asphttp://www.w3schools.com/ado/met_rs_comparebookmarks.asphttp://www.w3schools.com/ado/met_rs_close.asphttp://www.w3schools.com/ado/met_rs_clone.asphttp://www.w3schools.com/ado/met_rs_cancelupdate.asphttp://www.w3schools.com/ado/met_rs_cancelbatch.asphttp://www.w3schools.com/ado/met_rs_cancel.asphttp://www.w3schools.com/ado/met_rs_addnew.asphttp://www.w3schools.com/ado/prop_rs_stayinsync.asphttp://www.w3schools.com/ado/prop_rs_status.asphttp://www.w3schools.com/ado/prop_rs_state.asphttp://www.w3schools.com/ado/prop_rs_source.asphttp://www.w3schools.com/ado/prop_rs_sort.asp
  • 8/4/2019 ASP ADO SQL 2000

    33/51

  • 8/4/2019 ASP ADO SQL 2000

    34/51

    [ASP- ADO- ActiveX Data Objects]

    Kolej Komuniti Sabak Bernam | 34

    FieldChangeComplete Triggered after the value of a Field object change

    MoveComplete Triggered after the current position in the Recordset has changed

    RecordChangeComplete Triggered after a record has changed

    RecordsetChangeComplete Triggered after the Recordset has changed

    WillChangeField Triggered before the value of a Field object change

    WillChangeRecord Triggered before a record change

    WillChangeRecordset Triggered before a Recordset change

    WillMove Triggered before the current position in the Recordset changes

    Collections

    Collection Description

    Fields Indicates the number of Field objects in the Recordset object

    Properties Contains all the Property objects in the Recordset object

    The Fields Collection's Properties

    Property Description

    Count Returns the number of items in the fields collection. Starts at

    zero.

    Example:

    countfields=rs.Fields.Count

    Item(named_item/number) Returns a specified item in the fields collection.

    Example:

    itemfields=rs.Fields.Item(1)

    oritemfields=rs.Fields.Item("Name")

    The Properties Collection's Properties

    Property Description

    Count Returns the number of items in the properties collection. Starts at

    http://www.w3schools.com/ado/ev_rs_fieldchange.asphttp://www.w3schools.com/ado/ev_rs_fieldchange.asphttp://www.w3schools.com/ado/ev_rs_move.asphttp://www.w3schools.com/ado/ev_rs_recordchange.asphttp://www.w3schools.com/ado/ev_rs_recordsetchange.asphttp://www.w3schools.com/ado/ev_rs_recordsetchange.asphttp://www.w3schools.com/ado/ev_rs_fieldchange.asphttp://www.w3schools.com/ado/ev_rs_recordchange.asphttp://www.w3schools.com/ado/ev_rs_recordsetchange.asphttp://www.w3schools.com/ado/ev_rs_move.asphttp://www.w3schools.com/ado/ev_rs_move.asphttp://www.w3schools.com/ado/ev_rs_recordsetchange.asphttp://www.w3schools.com/ado/ev_rs_recordchange.asphttp://www.w3schools.com/ado/ev_rs_fieldchange.asphttp://www.w3schools.com/ado/ev_rs_recordsetchange.asphttp://www.w3schools.com/ado/ev_rs_recordchange.asphttp://www.w3schools.com/ado/ev_rs_move.asphttp://www.w3schools.com/ado/ev_rs_fieldchange.asp
  • 8/4/2019 ASP ADO SQL 2000

    35/51

    [ASP- ADO- ActiveX Data Objects]

    Kolej Komuniti Sabak Bernam | 35

    zero.

    Example:

    countprop=rs.Properties.Count

    Item(named_item/number) Returns a specified item in the properties collection.

    Example:

    itemprop = rs.Properties.Item(1)oritemprop=rs.Properties.Item("Name")

    ADO Stream Object

    Stream Object (ADO version 2.5)The ADO Stream Object is used to read, write, and manage a stream of binary data or text.

    A Stream object can be obtained in three ways:

    From a URL pointing to a document, a folder, or a Record object By instantiating a Stream object to store data for your application By opening the default Stream object associated with a Record object

    Syntax

    objectname.property

    objectname.method

    Properties

    Property Description

    CharSet Sets or returns a value that specifies into which character set

    the contents are to be translated. This property is only used

    with text Stream objects (type is adTypeText)

    EOS Returns whether the current position is at the end of the

    stream or not

    LineSeparator Sets or returns the line separator character used in a text

    Stream object

    http://www.w3schools.com/ado/prop_stream_charset.asphttp://www.w3schools.com/ado/prop_stream_charset.asphttp://www.w3schools.com/ado/prop_stream_eos.asphttp://www.w3schools.com/ado/prop_stream_eos.asphttp://www.w3schools.com/ado/prop_stream_lineseparator.asphttp://www.w3schools.com/ado/prop_stream_lineseparator.asphttp://www.w3schools.com/ado/prop_stream_eos.asphttp://www.w3schools.com/ado/prop_stream_charset.asp
  • 8/4/2019 ASP ADO SQL 2000

    36/51

    [ASP- ADO- ActiveX Data Objects]

    Kolej Komuniti Sabak Bernam | 36

    Mode Sets or returns the available permissions for modifying data

    Position Sets or returns the current position (in bytes) from the

    beginning of a Stream object

    Size

    Returns the size of an open Stream object

    State Returns a value describing if the Stream object is open or

    closed

    Type Sets or returns the type of data in a Stream object

    Methods

    Method Description

    Cancel Cancels an execution of an Open call on a Stream object

    Close Closes a Stream object

    CopyTo Copies a specified number of characters/bytes from one

    Stream object into another Stream object

    Flush Sends the contents of the Stream buffer to the associated

    underlying object

    LoadFromFile Loads the contents of a file into a Stream object

    Open Opens a Stream object

    Read Reads the entire stream or a specified number of bytes from

    a binary Stream object

    ReadText Reads the entire stream, a line, or a specified number of

    characters from a text Stream object

    SaveToFile Saves the binary contents of a Stream object to a file

    SetEOS Sets the current position to be the end of the stream (EOS)

    SkipLine Skips a line when reading a text Stream

    Write Writes binary data to a binary Stream object

    WriteText Writes character data to a text Stream object

    http://www.w3schools.com/ado/prop_stream_mode.asphttp://www.w3schools.com/ado/prop_stream_position.asphttp://www.w3schools.com/ado/prop_stream_size.asphttp://www.w3schools.com/ado/prop_stream_size.asphttp://www.w3schools.com/ado/prop_stream_state.asphttp://www.w3schools.com/ado/prop_stream_type.asphttp://www.w3schools.com/ado/prop_stream_type.asphttp://www.w3schools.com/ado/met_stream_cancel.asphttp://www.w3schools.com/ado/met_stream_cancel.asphttp://www.w3schools.com/ado/met_stream_close.asphttp://www.w3schools.com/ado/met_stream_copyto.asphttp://www.w3schools.com/ado/met_stream_copyto.asphttp://www.w3schools.com/ado/met_stream_flush.asphttp://www.w3schools.com/ado/met_stream_flush.asphttp://www.w3schools.com/ado/met_stream_loadfromfile.asphttp://www.w3schools.com/ado/met_stream_open.asphttp://www.w3schools.com/ado/met_stream_read.asphttp://www.w3schools.com/ado/met_stream_read.asphttp://www.w3schools.com/ado/met_stream_readtext.asphttp://www.w3schools.com/ado/met_stream_savetofile.asphttp://www.w3schools.com/ado/met_stream_seteos.asphttp://www.w3schools.com/ado/met_stream_skipline.asphttp://www.w3schools.com/ado/met_stream_write.asphttp://www.w3schools.com/ado/met_stream_writetext.asphttp://www.w3schools.com/ado/met_stream_writetext.asphttp://www.w3schools.com/ado/met_stream_write.asphttp://www.w3schools.com/ado/met_stream_skipline.asphttp://www.w3schools.com/ado/met_stream_seteos.asphttp://www.w3schools.com/ado/met_stream_savetofile.asphttp://www.w3schools.com/ado/met_stream_readtext.asphttp://www.w3schools.com/ado/met_stream_read.asphttp://www.w3schools.com/ado/met_stream_open.asphttp://www.w3schools.com/ado/met_stream_loadfromfile.asphttp://www.w3schools.com/ado/met_stream_flush.asphttp://www.w3schools.com/ado/met_stream_copyto.asphttp://www.w3schools.com/ado/met_stream_close.asphttp://www.w3schools.com/ado/met_stream_cancel.asphttp://www.w3schools.com/ado/prop_stream_type.asphttp://www.w3schools.com/ado/prop_stream_state.asphttp://www.w3schools.com/ado/prop_stream_size.asphttp://www.w3schools.com/ado/prop_stream_position.asphttp://www.w3schools.com/ado/prop_stream_mode.asp
  • 8/4/2019 ASP ADO SQL 2000

    37/51

    [ASP- ADO- ActiveX Data Objects]

    Kolej Komuniti Sabak Bernam | 37

    ADO Data Types

    The table below shows the ADO Data Type mapping between Access, SQL Server, and Oracle:

    DataType Enum Value Access SQLServer Oracle

    adBigInt 20 BigInt (SQL Server2000 +)

    adBinary 128 BinaryTimeStamp

    Raw *

    adBoolean 11 YesNo Bit

    adChar 129 Char Char

    adCurrency 6 Currency MoneySmallMoney

    adDate 7 Date DateTime

    adDBTimeStamp 135 DateTime (Access 97

    (ODBC))

    DateTime

    SmallDateTime

    Date

    adDecimal 14 Decimal *

    adDouble 5 Double Float Float

    adGUID 72 ReplicationID (Access97 (OLEDB)), (Access2000 (OLEDB))

    UniqueIdentifier (SQLServer 7.0 +)

    adIDispatch 9

    adInteger 3 AutoNumberIntegerLong

    Identity (SQL Server6.5)Int

    Int *

    adLongVarBinary 205 OLEObject Image Long Raw *Blob (Oracle 8.1.x)

    adLongVarChar 201 Memo (Access 97)Hyperlink (Access 97)

    Text Long *Clob (Oracle 8.1.x)

    adLongVarWChar 203 Memo (Access 2000(OLEDB))Hyperlink (Access2000 (OLEDB))

    NText (SQL Server 7.0+)

    NClob (Oracle 8.1.x)

    adNumeric 131 Decimal (Access 2000(OLEDB))

    DecimalNumeric

    DecimalIntegerNumberSmallInt

    adSingle 4 Single RealadSmallInt 2 Integer SmallInt

    adUnsignedTinyInt 17 Byte TinyInt

    adVarBinary 204 ReplicationID (Access97)

    VarBinary

    adVarChar 200 Text (Access 97) VarChar VarChar

    adVariant 12 Sql_Variant (SQLServer 2000 +)

    VarChar2

  • 8/4/2019 ASP ADO SQL 2000

    38/51

    [ASP- ADO- ActiveX Data Objects]

    Kolej Komuniti Sabak Bernam | 38

    adVarWChar 202 Text (Access 2000(OLEDB))

    NVarChar (SQL Server7.0 +)

    NVarChar2

    adWChar 130 NChar (SQL Server7.0 +)

    * In Oracle 8.0.x - decimal and int are equal to number and number(10).

    ADO Summary

    This tutorial has taught you how to access data in a database from a web site.

    You have learned how to display data from a database on a web site, and how to edit, add and deletethe data with ADO.

    ADO Examples

    Display

    Example 12 Display Records

  • 8/4/2019 ASP ADO SQL 2000

    39/51

  • 8/4/2019 ASP ADO SQL 2000

    40/51

    [ASP- ADO- ActiveX Data Objects]

    Kolej Komuniti Sabak Bernam | 40

    Example 14 Add Headers

    Add colors to the HTML table

    Example 15 Add Colors

    http://www.w3schools.com/ado/showasp.asp?filename=demo_display4http://www.w3schools.com/ado/showasp.asp?filename=demo_display4
  • 8/4/2019 ASP ADO SQL 2000

    41/51

    [ASP- ADO- ActiveX Data Objects]

    Kolej Komuniti Sabak Bernam | 41

    Queries

    Display records where "Companyname" starts with an A

    Example 16 Display Records Companyname starts with an A

    http://www.w3schools.com/ado/showasp.asp?filename=demo_query_1http://www.w3schools.com/ado/showasp.asp?filename=demo_query_1
  • 8/4/2019 ASP ADO SQL 2000

    42/51

    [ASP- ADO- ActiveX Data Objects]

    Kolej Komuniti Sabak Bernam | 42

    Display records where "Companyname" is > E

    Example 17 Display RecordsCompanyname > E

    http://www.w3schools.com/ado/showasp.asp?filename=demo_query_2http://www.w3schools.com/ado/showasp.asp?filename=demo_query_2
  • 8/4/2019 ASP ADO SQL 2000

    43/51

    [ASP- ADO- ActiveX Data Objects]

    Kolej Komuniti Sabak Bernam | 43

    Display only Spanish customers

    Example 18 Display Only Spanish Customers

    http://www.w3schools.com/ado/showasp.asp?filename=demo_query_3http://www.w3schools.com/ado/showasp.asp?filename=demo_query_3
  • 8/4/2019 ASP ADO SQL 2000

    44/51

    [ASP- ADO- ActiveX Data Objects]

    Kolej Komuniti Sabak Bernam | 44

    Let the user choose filter

    Example 19 Choose Filter

  • 8/4/2019 ASP ADO SQL 2000

    45/51

    [ASP- ADO- ActiveX Data Objects]

    Kolej Komuniti Sabak Bernam | 45

    conn.Open "Provider=SQLOLEDB.1;Password=sa;Persist Security Info=True;User

    ID=sa;Initial Catalog=Northwind;Data Source=(local)"

    set rs=Server.CreateObject("ADODB.recordset")

    sql="SELECT DISTINCT Country FROM Customers ORDER BY Country"

    rs.Open sql,conn

    country=request.form("country")

    %>

    Choose Country

    Companyname

    Contactname

    Country

  • 8/4/2019 ASP ADO SQL 2000

    46/51

    [ASP- ADO- ActiveX Data Objects]

    Kolej Komuniti Sabak Bernam | 46

    response.write("")

    response.write("" & rs.fields("companyname") & "")

    response.write("" & rs.fields("contactname") & "")

    response.write("" & rs.fields("country") & "")

    response.write("")

    rs.MoveNext

    loop

    rs.close

    conn.Close

    set rs=Nothing

    set conn=Nothing%>

    Sort

    Sort the records on a specified fieldname ascending

    Example 20 Sort (Specified fieldname ASC)

    http://www.w3schools.com/ado/showasp.asp?filename=demo_sort_1http://www.w3schools.com/ado/showasp.asp?filename=demo_sort_1
  • 8/4/2019 ASP ADO SQL 2000

    47/51

    [ASP- ADO- ActiveX Data Objects]

    Kolej Komuniti Sabak Bernam | 47

    Sort the records on a specified fieldname descending

    Example 21 Sort (Specified fieldname DESC)

    http://www.w3schools.com/ado/showasp.asp?filename=demo_sort_2http://www.w3schools.com/ado/showasp.asp?filename=demo_sort_2
  • 8/4/2019 ASP ADO SQL 2000

    48/51

    [ASP- ADO- ActiveX Data Objects]

    Kolej Komuniti Sabak Bernam | 48

    Let the user choose what column to sort on

    Example 22 Choose Column To Sort On

    Company

    Contact

  • 8/4/2019 ASP ADO SQL 2000

    49/51

    [ASP- ADO- ActiveX Data Objects]

    Kolej Komuniti Sabak Bernam | 49

    ID=sa;Initial Catalog=Northwind;Data Source=(local)"

    set rs=Server.CreateObject("ADODB.recordset")

    sql="SELECT Companyname,Contactname FROM Customers ORDER BY " & sort

    rs.Open sql,conn

    do until rs.EOF

    response.write("")

    for each x in rs.Fields

    response.write("" & x.value & "")

    next

    rs.MoveNext

    response.write("")

    loop

    rs.close

    conn.close

    %>

    Recordset Object

    GetRows

    Example 23 GetRows

  • 8/4/2019 ASP ADO SQL 2000

    50/51

    [ASP- ADO- ActiveX Data Objects]

    Kolej Komuniti Sabak Bernam | 50

    p=rs.GetRows(2,0)

    response.write("

    This example returns the value of the first column in the first two

    records:

    ")

    response.write(p(0,0))

    response.write("
    ")

    response.write(p(0,1))

    response.write("

    This example returns the value of the first three columns in the first

    record:

    ")

    response.write(p(0,0))

    response.write("
    ")

    response.write(p(1,0))

    response.write("
    ")

    response.write(p(2,0))

    rs.close

    conn.close

    %>

    GetString

    Example 24 GetString

    http://www.w3schools.com/ado/showasp.asp?filename=demo_display5http://www.w3schools.com/ado/showasp.asp?filename=demo_display5
  • 8/4/2019 ASP ADO SQL 2000

    51/51

    [ASP- ADO- ActiveX Data Objects]