0% found this document useful (0 votes)
148 views24 pages

Notes

The document provides information about the ADO Record object. It can hold a row in a Recordset, directory, or file system. Unlike previous versions of ADO, it allows access to datasets where the number of columns and data types can vary between rows. Properties and methods are described for accessing and manipulating data in the Record object. Collections like Fields and Properties are also summarized.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
148 views24 pages

Notes

The document provides information about the ADO Record object. It can hold a row in a Recordset, directory, or file system. Unlike previous versions of ADO, it allows access to datasets where the number of columns and data types can vary between rows. Properties and methods are described for accessing and manipulating data in the Record object. Collections like Fields and Properties are also summarized.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 24

ADO Record Object

Previous Next Chapter

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 the same data type. The Record object allows access to data-sets where the number of columns and/or the data type can be different from row to row.

Syntax
objectname.property objectname.method

Properties
Property ActiveConnection Mode ParentURL RecordType Source State Description Sets or returns which Connection object a Record object belongs to Sets or returns the permission for modifying data in a Record object Returns the absolute URL of the parent Record Returns the type of a Record object Sets or returns the src parameter of the Open method of a Record object Returns the status of a Record object

Methods
Method Cancel Close CopyRecord DeleteRecord GetChildren MoveRecord Description Cancels an execution of a CopyRecord, DeleteRecord, MoveRecord, or Open call Closes a Record object Copies a file or directory to another location Deletes a file or directory Returns a Recordset object where each row represents the files in the directory Moves a file or a directory to another location

Open

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

Collections
Collection Properties Fields Description A collection of provider-specific properties Contains all the Field objects in the Record object

The Fields Collection's Properties


Property Count Description 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) or itemfields = rec.Fields.Item("Name")

Previous Next Chapter

ADO Recordset Object


Previous Next Chapter

Examples
GetRows This example demonstrates how to use the GetRows method.

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.

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 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.

The cursor type can be set by the CursorType property or by the CursorType parameter in the Open method. Note: Not all providers support all methods or properties of the Recordset object.

Properties
Property AbsolutePage AbsolutePosition ActiveCommand ActiveConnection BOF Bookmark CacheSize Description Sets or returns a value that specifies the page number in the Recordset object Sets or returns a value that specifies the ordinal position of the current record in the Recordset object Returns the Command object associated with the Recordset Sets or returns a definition for a connection if the connection is closed, or the current Connection object if the connection is open Returns true if the current record position is before the first record, otherwise false Sets or returns a bookmark. The bookmark saves the position of the current record Sets or returns the number of records that can be cached

CursorLocation CursorType DataMember DataSource EditMode EOF Filter Index LockType MarshalOptions MaxRecords PageCount PageSize RecordCount Sort Source State Status StayInSync

Sets or returns the location of the cursor service Sets or returns the cursor type of a Recordset object Sets or returns the name of the data member that will be retrieved from the object referenced by the DataSource property Specifies an object containing data to be represented as a Recordset object Returns the editing status of the current record Returns true if the current record position is after the last record, otherwise false Sets or returns a filter for the data in a Recordset object Sets or returns the name of the current index for a Recordset object Sets or returns a value that specifies the type of locking when editing a record in a Recordset Sets or returns a value that specifies which records are to be returned to the server Sets or returns the maximum number of records to return to a Recordset object from a query Returns the number of pages with data in a Recordset object Sets or returns the maximum number of records allowed on a single page of a Recordset object Returns the number of records in a Recordset object Sets or returns the field names in the Recordset to sort on Sets a string value or a Command object reference, or returns a String value that indicates the data source of the Recordset object Returns a value that describes if the Recordset object is open, closed, connecting, executing or retrieving data Returns the status of the current record with regard to batch updates or other bulk operations Sets or returns whether the reference to the child records will change when the parent record position changes

Methods
Method AddNew Cancel CancelBatch CancelUpdate Clone Close CompareBookmarks Delete Find Description Creates a new record Cancels an execution Cancels a batch update Cancels changes made to a record of a Recordset object Creates a duplicate of an existing Recordset Closes a Recordset Compares two bookmarks Deletes a record or a group of records Searches for a record in a Recordset that satisfies a specified

criteria GetRows GetString Move MoveFirst MoveLast MoveNext MovePrevious NextRecordset Open Requery Resync Save Seek Supports Update UpdateBatch Copies multiple records from a Recordset object into a twodimensional array Returns a Recordset as a string Moves the record pointer in a Recordset object Moves the record pointer to the first record Moves the record pointer to the last record Moves the record pointer to the next record Moves the record pointer to the previous record Clears the current Recordset object and returns the next Recordset object by looping through a series of commands Opens a database element that gives you access to records in a table, the results of a query, or to a saved Recordset Updates the data in a Recordset by re-executing the query that made the original Recordset Refreshes the data in the current Recordset from the original database Saves a Recordset object to a file or a Stream object Searches the index of a Recordset to find a record that matches the specified values Returns a boolean value that defines whether or not a Recordset object supports a specific type of functionality Saves all changes made to a single record in a Recordset object Saves all changes in a Recordset to the database. Used when working in batch update mode

Events
Note: You cannot handle events using VBScript or JScript (only Visual Basic, Visual C++, and Visual J++ languages can handle events). Event EndOfRecordset FetchComplete FetchProgress FieldChangeComplete MoveComplete RecordChangeComplete RecordsetChangeComplete WillChangeField WillChangeRecord WillChangeRecordset Description Triggered when you try to move to a record after the last record Triggered after all records in an asynchronous operation have been fetched Triggered periodically in an asynchronous operation, to state how many more records that have been fetched Triggered after the value of a Field object change Triggered after the current position in the Recordset has changed Triggered after a record has changed Triggered after the Recordset has changed Triggered before the value of a Field object change Triggered before a record change Triggered before a Recordset change

WillMove

Triggered before the current position in the Recordset changes

Collections
Collection Fields Properties Description Indicates the number of Field objects in the Recordset object Contains all the Property objects in the Recordset object

The Fields Collection's Properties


Property Count Description 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) or itemfields=rs.Fields.Item("Name")

The Properties Collection's Properties


Property Count Description Returns the number of items in the properties collection. Starts at zero. Example: countprop=rs.Properties.Count Item(named_item/number) Returns a specified item in the properties collection. Example: itemprop = rs.Properties.Item(1) or itemprop=rs.Properties.Item("Name")

Previous Next Chapter

<!DOCTYPE html> <html>

<body> <% set conn=Server.CreateObject("ADOD B.Connection") conn.Provider="Microsoft.Jet.OLE DB.4.0" conn.Open(Server.Mappath("/db/ northwind.mdb")) set rs = Server.CreateObject("ADODB.reco rdset") rs.Open "Select * from Customers", conn 'The first number indicates how many records to copy 'The second number indicates what recordnumber to start on p=rs.GetRows(2,0)

response.write("<p>This example returns the value of the first column in the first two records:</p>") response.write(p(0,0)) response.write("<br />") response.write(p(0,1)) response.write("<p>This example returns the value of the first three columns in the first record:</p>") response.write(p(0,0)) response.write("<br />") response.write(p(1,0)) response.write("<br />") response.write(p(2,0)) rs.close conn.close %>

</body> </html>ADO Stream Object


Previous Next Chapter

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 CharSet Description 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) Returns whether the current position is at the end of the stream or not Sets or returns the line separator character used in a text Stream object Sets or returns the available permissions for modifying data Sets or returns the current position (in bytes) from the beginning of a Stream object Returns the size of an open Stream object Returns a value describing if the Stream object is open or closed Sets or returns the type of data in a Stream object

EOS LineSeparator Mode Position Size State Type

Methods
Method Description

Cancel Close CopyTo Flush LoadFromFile Open Read ReadText SaveToFile SetEOS SkipLine Write WriteText

Cancels an execution of an Open call on a Stream object Closes a Stream object Copies a specified number of characters/bytes from one Stream object into another Stream object Sends the contents of the Stream buffer to the associated underlying object Loads the contents of a file into a Stream object Opens a Stream object Reads the entire stream or a specified number of bytes from a binary Stream object Reads the entire stream, a line, or a specified number of characters from a text Stream object Saves the binary contents of a Stream object to a file Sets the current position to be the end of the stream (EOS) Skips a line when reading a text Stream Writes binary data to a binary Stream object Writes character data to a text Stream object

Previous Next Chapter

ADO Data Types


Previous Next Chapter
The table below shows the ADO Data Type mapping between Access, SQL Server, and Oracle: DataType Enum adBigInt adBinary adBoolean adChar adCurrency adDate adDBTimeStamp adDecimal adDouble adGUID Value 20 128 11 129 6 7 135 14 5 72 Double ReplicationID (Access Float UniqueIdentifier (SQL Currency Date DateTime (Access 97 (ODBC)) YesNo Access SQLServer BigInt (SQL Server 2000 +) Binary TimeStamp Bit Char Money SmallMoney DateTime DateTime SmallDateTime Date Decimal * Float Char Raw * Oracle

97 (OLEDB)), (Access 2000 (OLEDB)) adIDispatch adInteger 9 3 AutoNumber Integer Long OLEObject Memo (Access 97) Hyperlink (Access 97) Memo (Access 2000 (OLEDB)) Hyperlink (Access 2000 (OLEDB)) Decimal (Access 2000 (OLEDB))

Server 7.0 +)

Identity (SQL Server 6.5) Int Image Text

Int *

adLongVarBinary adLongVarChar adLongVarWChar

205 201 203

Long Raw * Blob (Oracle 8.1.x) Long * Clob (Oracle 8.1.x)

NText (SQL Server 7.0 NClob (Oracle 8.1.x) +)

adNumeric

131

Decimal Numeric

Decimal Integer Number SmallInt

adSingle adSmallInt adUnsignedTinyInt adVarBinary adVarChar adVariant adVarWChar adWChar

4 2 17 204 200 12 202 130

Single Integer Byte ReplicationID (Access 97) Text (Access 97)

Real SmallInt TinyInt VarBinary VarChar Sql_Variant (SQL Server 2000 +) VarChar VarChar2

Text (Access 2000 (OLEDB))

NVarChar (SQL Server NVarChar2 7.0 +) NChar (SQL Server 7.0 +)

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

Previous Next Chapter

You Have Learned ADO, Now What?


Previous Next Chapter

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 delete the data with ADO. For more information on ADO, please look at our ADO examples.

Now You Know ADO, What's Next?


The next step is to learn SQL. SQL is a standard computer language for accessing and manipulating database systems. SQL statements are used to retrieve and update data in a database. SQL works with database programs like MS Access, DB2, Informix, MS SQL Server, Oracle, Sybase, and other database systems. If you want to learn more about SQL, please visit our SQL tutorial.

Previous Next Chapter

ADO Examples
Previous Next Chapter
Display Display records Display records in an HTML table Add headers to the HTML table Add colors to the HTML table Queries Display records where "Companyname" starts with an A Display records where "Companyname" is > E Display only Spanish customers Let the user choose filter Sort Sort the records on a specified fieldname ascending Sort the records on a specified fieldname descending Let the user choose what column to sort on

Recordset Object GetRows GetString

Previous Next Chapter


<!DOCTYPE html> <html> <body> <% set conn=Server.CreateObject("ADODB.Connection") conn.Provider="Microsoft.Jet.OLEDB.4.0" conn.Open(Server.Mappath("/db/northwind.mdb")) set rs = Server.CreateObject("ADODB.recordset") rs.Open "Select * from Customers", conn do until rs.EOF for each x in rs.Fields Response.Write(x.name) Response.Write(" = ") Response.Write(x.value & "<br />") next Response.Write("<br />") rs.MoveNext loop rs.close conn.close %> </body> </html><!DOCTYPE html> <html> <body> <% set conn=Server.CreateObject("ADODB.Connection") conn.Provider="Microsoft.Jet.OLEDB.4.0" conn.Open(Server.Mappath("/db/northwind.mdb"))

set rs = Server.CreateObject("ADODB.recordset") rs.Open "SELECT Companyname, Contactname FROM Customers", conn %> <table border="1" width="100%"> <%do until rs.EOF%> <tr> <%for each x in rs.Fields%> <td><%Response.Write(x.value)%></td> <%next rs.MoveNext%> </tr> <%loop rs.close conn.close %> </table> </body> </html><!DOCTYPE html> <html> <body> <% set conn=Server.CreateObject("ADODB.Connection") conn.Provider="Microsoft.Jet.OLEDB.4.0" conn.Open(Server.Mappath("/db/northwind.mdb")) set rs = Server.CreateObject("ADODB.recordset") sql="SELECT Companyname, Contactname FROM Customers" rs.Open sql, conn %> <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 rs.close conn.close %> </table> </body> </html><!DOCTYPE html> <html> <body> <% set conn=Server.CreateObject("ADODB.Connection") conn.Provider="Microsoft.Jet.OLEDB.4.0" conn.Open(Server.Mappath("/db/northwind.mdb")) set rs = Server.CreateObject("ADODB.recordset") sql="SELECT Companyname, Contactname FROM Customers" rs.Open sql, conn %> <table border="1" width="100%" bgcolor="#fff5ee"> <tr> <%for each x in rs.Fields response.write("<th align='left' bgcolor='#b0c4de'>" & 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 rs.close conn.close %> </table>

</body> </html><!DOCTYPE html> <html> <body> <% set conn=Server.CreateObject("ADODB.Connection") conn.Provider="Microsoft.Jet.OLEDB.4.0" conn.Open(Server.Mappath("/db/northwind.mdb")) set rs = Server.CreateObject("ADODB.recordset") sql="SELECT Companyname, Contactname FROM Customers WHERE CompanyName LIKE 'A%'" rs.Open sql, conn %> <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 rs.close conn.close %> </table> </body> </html><!DOCTYPE html> <html> <body> <% set conn=Server.CreateObject("ADODB.Connection")

conn.Provider="Microsoft.Jet.OLEDB.4.0" conn.Open(Server.Mappath("/db/northwind.mdb")) set rs = Server.CreateObject("ADODB.recordset") sql="SELECT Companyname, Contactname FROM Customers WHERE CompanyName>'E'" rs.Open sql, conn %> <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 rs.close conn.close %> </table> </body> </html><!DOCTYPE html> <html> <body> <% set conn=Server.CreateObject("ADODB.Connection") conn.Provider="Microsoft.Jet.OLEDB.4.0" conn.Open(Server.Mappath("/db/northwind.mdb")) set rs = Server.CreateObject("ADODB.recordset") sql="SELECT Companyname, Contactname FROM Customers WHERE Country='Spain'" rs.Open sql, conn %>

<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 rs.close conn.close %> </table> </body> </html><!DOCTYPE html> <html> <body> <% set conn=Server.CreateObject("ADODB.Connection") conn.Provider="Microsoft.Jet.OLEDB.4.0" conn.Open(Server.Mappath("/db/northwind.mdb")) set rs=Server.CreateObject("ADODB.recordset") sql="SELECT DISTINCT Country FROM Customers ORDER BY Country" rs.Open sql,conn country=request.form("country") %> <form method="post"> Choose Country <select name="country"> <% do until rs.EOF response.write("<option") if rs.fields("country")=country then

response.write(" selected") end if response.write(">") response.write(rs.fields("Country")) rs.MoveNext loop rs.Close set rs=Nothing %> </select> <input type="submit" value="Show customers"> </form> <% if country<>"" then sql="SELECT Companyname,Contactname,Country FROM Customers WHERE country='" & country & "'" set rs=Server.CreateObject("ADODB.Recordset") rs.Open sql,conn %> <table width="100%" cellspacing="0" cellpadding="2" border="1"> <tr> <th>Companyname</th> <th>Contactname</th> <th>Country</th> </tr> <% do until rs.EOF response.write("<tr>") response.write("<td>" & rs.fields("companyname") & "</td>") response.write("<td>" & rs.fields("contactname") & "</td>") response.write("<td>" & rs.fields("country") & "</td>") response.write("</tr>") rs.MoveNext loop rs.close conn.Close set rs=Nothing set conn=Nothing%> </table> <% end if %> </body>

</html><!DOCTYPE html> <html> <body> <% set conn=Server.CreateObject("ADODB.Connection") conn.Provider="Microsoft.Jet.OLEDB.4.0" conn.Open(Server.Mappath("/db/northwind.mdb")) set rs = Server.CreateObject("ADODB.recordset") sql="SELECT Companyname, Contactname FROM Customers ORDER BY CompanyName" rs.Open sql, conn %> <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 rs.close conn.close %> </table> </body> </html><!DOCTYPE html> <html> <body> <% set conn=Server.CreateObject("ADODB.Connection") conn.Provider="Microsoft.Jet.OLEDB.4.0" conn.Open(Server.Mappath("/db/northwind.mdb"))

set rs = Server.CreateObject("ADODB.recordset") sql="SELECT Companyname, Contactname FROM Customers ORDER BY CompanyName DESC" rs.Open sql, conn %> <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 rs.close conn.close %> </table> </body> </html><!DOCTYPE html> <html> <body> <table border="1" width="100%" bgcolor="#fff5ee"> <tr> <th align="left" bgcolor="#b0c4de"> <a href="demo_sort_3.asp?sort=companyname">Company</a> </th> <th align="left" bgcolor="#b0c4de"> <a href="demo_sort_3.asp?sort=contactname">Contact</a> </th> </tr> <% if request.querystring("sort")<>"" then sort=request.querystring("sort")

else sort="companyname" end if set conn=Server.CreateObject("ADODB.Connection") conn.Provider="Microsoft.Jet.OLEDB.4.0" conn.Open(Server.Mappath("/db/northwind.mdb")) 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("<tr>") for each x in rs.Fields response.write("<td>" & x.value & "</td>") next rs.MoveNext response.write("</tr>") loop rs.close conn.close %> </table> </body> </html><!DOCTYPE html> <html> <body> <% set conn=Server.CreateObject("ADODB.Connection") conn.Provider="Microsoft.Jet.OLEDB.4.0" conn.Open(Server.Mappath("/db/northwind.mdb")) set rs = Server.CreateObject("ADODB.recordset") rs.Open "Select * from Customers", conn 'The first number indicates how many records to copy 'The second number indicates what recordnumber to start on p=rs.GetRows(2,0) response.write("<p>This example returns the value of the first column in the first two records:</p>")

response.write(p(0,0)) response.write("<br />") response.write(p(0,1)) response.write("<p>This example returns the value of the first three columns in the first record:</p>") response.write(p(0,0)) response.write("<br />") response.write(p(1,0)) response.write("<br />") response.write(p(2,0)) rs.close conn.close %> </body> </html><!DOCTYPE html> <html> <body> <% set conn=Server.CreateObject("ADODB.Connection") conn.Provider="Microsoft.Jet.OLEDB.4.0" conn.Open(Server.Mappath("/db/northwind.mdb")) set rs = Server.CreateObject("ADODB.recordset") rs.Open "SELECT Companyname, Contactname FROM Customers", conn str=rs.GetString(,,"</td><td>","</td></tr><tr><td>"," ") %> <table border="1" width="100%"> <tr> <td><%Response.Write(str)%></td> </tr> </table> <% rs.close conn.close set rs = Nothing set conn = Nothing %>

</body> </html>

You might also like