|
|
|
|
The RecordSet Object The following sample provides an example of the use of these properties: <% If intPageSize = 0 Then
rstMyCursor.PageSize = intPageSize
Session ( "intPage" ) = 1
End If rstMyCursor.AbsolutePage =Session("intPage") %> <TITLE>Using Pages In Recordsets</TITLE> </HEAD> Page Count : <%= rstMyCursor.PageCount %> <BR> Record Count : <%= rstMyCursor.RecordCount %> <BR> Current Page : <%= Session("intPage") %> <BR> <FORM METHOD="post"> <INPUT
TYPE="submit" NAME="btnNavigate" VALUE="Next"> </FORM> <TABLE
BORDER=1 BORDERCOLOR="#000000" CELLSPACING="5" CELLPADDING="5"> <% For Each strField In rstMyCursor.Fields % >
<TH ALIGN="center"> </TH> </TR> < % For intCounter = 1 To rstMyCursor.PageSize %>
<TR>
<TD>
</TD> <% If rstMyCursor.EOF Then Exit For End If Next
The Filter property of the Recordset Object can filter records from a recordset based on certain criteria. You can use either a criteria constant or a criteria string to filter records. Criteria constants are predefined ways of filtering records, based upon their current status. For example, the records can be filtered to display only edited records, records that have not yet been updated, etc. The criteria string is a user-defined criteria. The syntax for setting the Filter property is: rstMyCursor.Filter = [CriteriaConstant I CriteriaString]
The following table lists the predefined criteria constants:
The criteria string can be any comparison expression on the recordset. The following example filters a recordset of employers for managers whose salary is greater than 10,000. rstMyCursor.Filter = "EmpDesagnation= 'Manager' AND EmpSalary > 10000"
Data manipulation is extremely simple with ADO. The Recordset Object handles most situations very wisely, hence avoiding errors. For example, if you change values in the current record and move to the next record without updating the current one first, the Recordset Object automatically calls the Update method before moving.
To edit a value in a recordset simply assign it a new value. This value can be any valid expression that returns the data type of the field. rstMyCursor("FieldName") = Value
The AddNew method of the Recordset Object is used to add records to the recordset. The method is optionally passed a list of fields and their respective values, much like the SQL Insert Into statement. If these parameters are passed, invoking the Update method is not required after adding the record. If these parameters are not passed, you can assign values to each field using the same syntax as when editing the record. In this case, the Edi tMode property of the Recordset Object is set to adEdi tAdd. This does not change until the buffer is added to the database (by updating it). rstMyCursor.AddNew Fields, Values
The Delete method can delete a set of records. The syntax for deleting records is: rstMyCursor.Delete AffectRecords The optional AffectRecords argument is a constant that defines which records should be affected by the Delete method. By default, the current record is deleted
(adAffeetCurrent). The current filtered set can be deleted by using
The Update method saves any changes made to the current record. The syntax is similar to that of the AddNew method: rstMyCursor.Update Fields, Values The UpdateBatch method can update records in groups. Hence, you can modify all records that you wish to and then update all of them at once. rstMyCursor.UpdateBatch AffectedRecords The optional AffectedRecords constant takes the same values as that of the Delete method. One additional value that it can take is adAf
fectAll, which updates all records. |
|||||||||||||||