Recommended: In ASP, it implements exporting data from dbf database to sql table Description: The dbf database structure must be consistent with the sql table. The following is the reference content: <% Dim conndbf_dbf, Driver_dbf, SourceType_dbf, DBPath_dbf dim Conn_
8.4.3 Creating a record setIt is very easy to create a record set, which is achieved by calling the Open method of the Recordset object:
Recordset.Open [Source], [ActiveConnection], [CursorType], [LockType], [Options]
The parameters and descriptions are shown in Table 8-3:
Table 8-3 Parameters and descriptions of Open method
parameter
illustrate
Source
Data source. It can be a table name in the database, a stored query or procedure, a SQL string, a Command object, or other command object suitable for the provider
ActiveConnection
The connection used by the record set. It can be a connection string or an open Connection object
CursorType
The type of cursor used. Must be one of the defined cursor types, the default value is adForwardOnly
LockType
The lock type used. Must be one of the defined lock types, the default value is adLockReadOnly
Options
Tell the provider what the content of the Source parameter is, such as tables, text strings, etc.
For example, to open the recordset on the authors table in the database pubs:
Dim rsAuthors
Set rsAuthors = Server.CreateObject(ADODB.Recordset)
rsAuthors.Open authors, strConn
' Do something here
rsAuthors.Close
Set rsAuthors = Nothing
Note that there are several parameters that are not specified. In fact, all parameters are optional, and you can set the corresponding property values for the record set before opening them:
Dim rsAuthors
Set rsAuthors = Server.CreateObject(ADODB.Recordset)
With rsAuthors
.Source = authors
.ActiveConnection = strConn
.CursorType = adOpenForwardOnly
.LockType = adLockReadOnly
.Open
End With
' Do something here
rsAuthors.Close
Set rsAuthors = Nothing
Once the record set is opened, the current pointer is automatically located on the first record. If there is no record in the record set, both EOF and BOF attributes are True:
rsAuthors.Open authors, strConn
If rsAuthors.BOF and rsAuthors.EOF Then
' Recordset is empty
End If
1. Options parameter
The Options parameter of the Open method allows specifying the command text content. It can be one of the following CommandTypeEnum constants:
adCmdText: Text commands, such as SQL strings.
adCmdTable: table name.
adCmdStoredProc: Stored procedure name.
adCmdFile: The file name of the saved record set.
adCmdTableDirect: table name.
adCmdURLBind: URL address.
The difference between adCmdTable and adCmdTableDirect is very small. If you want to use all columns in a table, using adCmdTableDirect will make the run faster because ADO performs some internal optimizations.
If no command type is specified, ADO must calculate the type of command executed, which will result in additional overhead.
There are two more options here: adCmdUnspecified means that there is no specified type; adCmdUnknow means that the type of the command is unknown. They may not be used in general.
Additional options
The Options parameter can be any of the above constants, but the following ExecuteOptionEnum constants can also be added:
adAsyncExcute: execute commands asynchronously.
adAsyncFetch: After obtaining the initial row set, obtain the remaining rows asynchronously.
adAsyncFetchBlocking: Except for getting records and not preventing the command from running, the others are similar to adAsyncFetch.
adExechteNoRecords: The command returns no records.
Asynchronous processing means that operations are performed in the background, you can run commands and then continue other work without waiting for them to complete (synchronous operation). This is particularly convenient when creating a user interface, because it can be returned from the command execution to display some content to the user while the data acquisition is still in the background. This is not very useful for ASP programmers when returning recordsets, because the scripting language does not support ADO events, so it is not known when the record set has completed the fill shift. When processing update, delete or insert data commands and not returning a record set, asynchronous operations can be used, i.e. only if you don't care about the results.
On the other hand, the adExecuteNoRecords option is very useful. It tells ADO to execute commands that do not return any data. Therefore, there is no need to create a record set (maybe empty in short). This speeds up running query operations for updates or data additions.
To add one of these options, you can use the Or symbol (equivalent to the plus sign)
adCmdStoredProc Or adExecuteNoRecords
adCmdStoreProc adExecuteNoRecords
In the next chapter, you will see a more detailed introduction to the related content, as this will be more useful when dealing with commands (rather than record sets).
2. Move in the record set
Once a record set is opened, it is often necessary to traverse each record. This requires the use of the EOF attribute. When the end of the record set is reached, EOF becomes True, because a loop can be created like this:
rsAuthors.Open authors, strConn
While Not rsAuthors.EOF
Response.Write rsAuthors(au_lname:) & , & _
rsAuthors(au_fname) & <BR>
rsAuthors.MoveNext
Wend
The above example loops until the EOF attribute is True before exiting. The MoveNext method is used to move to the next record.
If the record set allows backward movement, you can use the MovePrevious method. In this case, the BOF attribute value needs to be detected in the loop. There are also MoveFirst and MoveLast methods that move to the first and last records respectively:
rsAuthors.Open authors, strConn, adOpenDynamic
' Now on first record
rsAuthors.MoveLast
' Now on last record
rsAuthors.MovePrevious
rsAuthors.MovePrevious
' Now three rows from the end of the recordset
rsAuthors.MoveFirst
' Back at the beginning again
3. Use Fields Collections
The Fields collection contains Fields objects for each field (column) in the record set. The Fields collection is the default collection of recordsets, so it can be omitted when accessing fields, just like in the While...Wend example above. Therefore, there are multiple ways to access fields:
rsAuthors.Fields(au_lname).Value
rsAuthors(au_lname).Value
rsAuthors(1).Value
rsAuthors.Fields(1).Value
You can use the field name, or use its bits in the collection
Share: ASP implements sending email notifications while submitting forms to the database The following is the quoted content: <% dim objCDOMail Set objCDOMail = Server.CreateObject(CDONTS.NewMail) objCDOMail.From =xxx@h