Download presentation
Presentation is loading. Please wait.
1
Chapter 10 ASP and Data Store Access
Using Databases: Databases are specially designed to store massive amounts of information efficiently. Many commercial databases are available, including Access, Microsoft SQL-server, Oracle, and Informix to name just a few. It is possible to read and modify the contents of the database through an ASP page. This is an amazingly useful function of ASP. The differences between flat file databases and Relational databases and explore the advantages of using databases as opposed to the other three methods.
2
Relational Databases The most useful feature of ASP is the capability for an ASP page to easily interact with Databases. The DATABASE is a collection of information that can easily be queried and modified. When using a database you can do only four things: retrieve data, insert data, update existing data and delete data. A table is two dimensional matrix that is used to store information in a database. A Record is a single instance of an object and is represented in a database by a row. A field is a single property of an object, represented by a column in a database table.
3
Universal Data Access Universal Data Access (UDA) is Microsoft's model or framework for a single uniform application program interface to different software makers' databases, both relational and nonrelational. UDA is the database access part of Microsoft's Component Object Model (com), an overall framework for creating and distributing object-oriented programming programs in a network. UDA consists mainly of the high-level interface, ActiveX Data Objects (ADO) and the lower-level services called OLE DB. IBM, Oracle, and other companies have provided database bridges that interface with OLE DB.
4
Universal Data Access Builds on the ODBC
Universal Data Access is a strategy that includes and builds on the successful foundation of ODBC. ODBC successes include the following: Establishing a market standard for database access. There are more than 170 ODBC drivers available today, providing access to a broad range of data. Achieving portability, so applications can scale to new database platforms as an organization's requirements change. Responding to customers' needs by steadily adding new features and performance improvements to enable better database applications.
5
OLE DB OLE DB is the Microsoft strategic system-level programming interface to data across the organization. OLE DB is an open specification designed to build on the success of ODBC by providing an open standard for accessing all kinds of data. ODBC was created to access relational databases. OLE DB is designed for relational and nonrelational information sources, including: mainframe ISAM/VSAM and hierarchical databases; and file system stores; text, graphical, and geographical data; custom business objects.
6
OLE DB
7
ADO Activex Data Object is specifically used as means to communicate and manipulate a database. The types of databases ADO will allow your ASP program to interact include Access, MySQL, and MSSQL to name a few. In this we will be connecting to an Access database, so you will need to have access to Access
8
The Recordset object The ADO Recordset object is used to hold a set of records from a database table. A Recordset object consist of records and columns (fields). In ADO, this object is the most important and the one used most often to manipulate data from a database. Dim conn Set conn=server.createobject(“adodb.connection”) Dim objrecordset 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.
9
The Recordset object Recordset objects can support two types of updating: Immediate updating - all changes are written immediately to the database once you call the Update method. Batch updating - the provider will cache multiple changes and then send them to the database 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 users will still be visible. Static cursor - Provides a static copy of a recordset for you to use to find data or generate reports. Additions, changes, or deletions by other users will not be visible. This is the only type of 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.
10
Data link File The Microsoft Data Access Components (MDAC) provide the Data Link Properties dialog box as the common user interface for specifying connection information to a data provider on Windows 2000 and later operating systems. You can use the Data Link Properties dialog box to save connection information in a universal data link (.udl) file.
11
To create a Universal Data Link (.udl) file
Right-click the Windows 2000 desktop, point to New, and then click Text Document. A new file is created by default (New Text Document.txt). On the Toolsmenu, click Folder Options. On the Viewtab, clear the Hide file extensions for known file types check box and then click OK. Right-click the Text Document you created in step 1, choose Rename, and then change the name and extension of the file to: (Data Link.UDL). A warning might appear, explaining that changing file extensions could cause files to become unusable. Disregard this warning. You can store the (Data Link.UDL) file anywhere on your system or network. Double-click the (Data Link.UDL) file or you can optionally right-click it, and then click Properties. This opens the Data Link Properties dialog box. You are now ready to connect to your data source.
12
To configure a universal data link (.udl) file
Double-click the universal data link (.udl) file. The Data Link Properties dialog box opens, displaying the following tabs: Provider, Connection, Advanced, and All. Choose Next to navigate from tab to tab. On the Provider tab, select a database provider. On the Connection tab, either select the data source name (DSN) of an available Provider, or enter a custom connection string. Valid DSNs for providers that are pre-defined on your system are displayed in the Use Data Source drop-down list. Use the Advanced tab to view and set other initialization properties for your data. Use the All tab to review and edit all OLE DB initialization properties available for your OLE DB provider. Choose OK to save the connection string to the Universal Data Link (.udl) file.
13
Active connection The ActiveConnection property sets or returns a string or variant that tells which Connection object the Record object belongs to. If the connection is closed, it sets or returns a string definition for a connection. If the connection is open it sets or returns a variant that is a reference to the current Connection object. Tip: The ActiveConnection parameter of the Open method of the Record object can also be used to set this property.
14
The ActiveConnection property tells which Connection object the Command object belongs to.
If the connection is closed, it sets or returns a definition for a connection. If the connection is open it sets or returns the current Connection object. Syntax objcommand.ActiveConnection <% set conn=Server.CreateObject("ADODB.Connection") conn.Provider="Microsoft.Jet.OLEDB.4.0" conn.Open "c:/webdata/northwind.mdb" set comm=Server.CreateObject("ADODB.Command") comm.ActiveConnection=conn response.write(comm.ActiveConnection) conn.close %>
15
BOF and EOF Properties The BOF property returns True (-1) if the current record position is before the first record in the Recordset, otherwise it returns False (0). The EOF property returns True (-1) if the current record position is after the last record in the Recordset, otherwise it returns False (0). Note: The BOF and EOF properties are set to True if you open an empty Recordset. RecordCount property is zero. Note: If a Recordset holds at least one record, the first record is the current and the BOF and EOF properties are False. Syntax objRecordset.BOF or objRecordset.EOF
16
<table border="1" width="100%">
<% set conn=Server.CreateObject("ADODB.Connection") conn.Provider="Microsoft.Jet.OLEDB.4.0" conn.Open(Server.Mappath("northwind.mdb")) set rs = Server.CreateObject("ADODB.recordset") sql="SELECT Companyname, Contactname FROM Customers" rs.Open sql, conn %> <table border="1" width="100%"> <%while rs.EOF=false%> <tr> <%for each x in rs.Fields%> <td><%Response.Write(x.value)%></td> <%next rs.MoveNext%> </tr> <%wend rs.close conn.close %>
17
Moving through Records
we saw how to step through a recordset using the MoveNext method. But what about other ways of moving? In fact, the Recordset object gives us four very easy-to-use methods that allow us to move the cursor backwards and forwards through its records: The MovePrevious and MoveNext methods allow us to move the cursor from the current record to the record immediately preceding or immediately after The MoveFirst and MoveLast methods move the cursor directly to the first or last record in the recordset These methods don't require any arguments. For example, and as we've already seen, we call the MoveNext method, pure and simple, like this: objRS.MoveNext
18
In addition, to these, there is a fifth method, called Move
In addition, to these, there is a fifth method, called Move. The Move method allows us to make the cursor jump over a specified number of records from its current position (or some other specified position). It has two parameters, and its syntax is as follows: objRecordset.Move NumRecords, Start Here, objRecordset is the name of our Recordset object. The first parameter, NumRecords, specifies the size of the jump – that is, the number of records that we want to jump. The second parameter, Start, specifies the point that you wish the move to start from. For example, if we want the cursor to jump forward two places from the current record we'd use the following: objRS.Move 2 Alternatively, if we wanted to jump back three records (and if our recordset doesn't have a 'forward-only cursor type!) then we could use this: objRS.Move -3 Note that the Start parameter is optional.
19
Finding Record The Find method searches for a record in a Recordset that satisfies a specified criteria. If the search is successful, the record pointer will point to the first found record. Note: A current row position (like MoveFirst) must be set before calling this method, otherwise an error will occur. Syntax objRecordset.Find(criteria,skiprows,direction,start)
20
Parameter Description
criteriaRequired. The column name, comparison operator, and value to use in the search. Examples: "Country='Norway'" "Date>#7/22/97#" "Country LIKE N*“ Note: This method does not support multi-column searches (AND or OR) Skiprows Optional. Specifies how many records beyond the current record to skip before beginning the search. Default is 0 Direction Optional. A SearchDirectionEnum value that specifies the search directionstartOptional. The starting position for the search SearchDirectionEnum Values Constant Value Description adSearchBackward -1 Searches backward from the starting position. Stops at the beginning of the Recordset. If no match, the record pointer is placed at the beginning of the Recordset adSearchForward 1 Searches forward from the starting position Stops at the end of the Recordset. If no match, the record pointer is placed at the end of the Recordset
21
Recordset Filtering The Filter property sets or returns a variant that contains a filter for the data in a Recordset object. The filter allows you to select records that fit a specific criteria. The Filter property can contain one of the following: A criteria string An array of bookmarks A FilterGroupEnum value Examples of a criteria string: rs.Filter="Lastname='Smith'" rs.Filter="Lastname='Smith' AND Birthdate >= #4/10/70#" rs.Filter="Lastname='Jonson' OR Lastname='Johnson'" rs.Filter= "Lastname LIKE Jon*" rs.Filter="[Company Name]='Alfred Futterkiste' OR Orders>$300.00"
22
Example of an array of bookmarks:
dim fname(10) fname(2)=rs.Bookmark rs.Filter=fname(2) When the Filter property is set, the cursor moves to the first record in the filtered Recordset. And, when the Filter property is cleared, the cursor moves to the first record in the unfiltered Recordset.
23
Thank you & Best wishes...
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.