VB Tutorial: asynchronous data loading

Source: Internet
Author: User

VB Tutorial: asynchronous data loading

Asynchronous loading is a Data Loading Method of ADO. It is mainly controlled by the options parameter of the record set!

The format in ADO210.CHM is as follows:

Recordset. OpenSource, ActiveConnection, CursorType, LockType, Options

Options

Optional. The Long value indicates the method in which the provider calculates the Source parameter (if this parameter represents content other than the Command object), or indicates that the Recordset should be restored from the previously saved file. It can be one or more [blocked ads]

CommandTypeEnum or ExecuteOptionEnum values. These values can be combined by the bitwise AND operator.

ExecuteOptionEnum

Specifies how the provider executes commands.

Constant Value description

AdAsyncExecute0x10 indicates that the command will be executed asynchronously.

This value cannot be combined with the CommandTypeEnum value adCmdTableDirect.

AdAsyncFetch0x20 indicates that the remaining rows after the specified initial quantity in the CacheSize attribute will be retrieved asynchronously.

AdAsyncFetchNonBlocking0x40 indicates that the main thread will never be blocked during retrieval. If the requested row is not retrieved, the current row will automatically move to the end of the file.

If you enable Recordset from a Stream that contains persistent storage Recordset, adAsyncFetchNonBlocking does not work. This operation is synchronized and blocked.

When the adCmdTableDirect option is used to open Recordset, adAsynchFetchNonBlocking does not work.

AdExecuteNoRecords0x80 indicates that the command text does not return line commands or stored procedures (for example, commands that only insert data ). If any rows are retrieved, they are discarded and no response is returned.

AdExecuteNoRecords can only be passed to the Command or Connection Execute method as an optional parameter.

AdExecuteStream0x400 indicates that the command execution result should be returned as a stream.

AdExecuteStream can only be passed to the Execute method of Command as an optional parameter.

AdExecuteRecord indicates that CommandText is a command or stored procedure that returns a single row that should be returned as a Record object.

AdOptionUnspecified-1 indicates that no command is specified.

CommandTypeEnum

Specifies the method for interpreting command parameters.

Constant Value description

The adCmdUnspecified-1 does not specify arguments for the command type.

AdCmdText1 calculates CommandText based on the text definition of the command or stored procedure call.

AdCmdTable2 calculates CommandText by table name. All columns in this table are returned by an internal SQL query.

AdCmdStoredProc4 calculates CommandText Based on the name of the stored procedure.

AdCmdUnknown8 default value. Indicates that the command type in the CommandText attribute is unknown.

Ad1_file256 calculates CommandText Based on the name of the persistent Recordset file. It is only used with Recordset. Open or Requery.

AdCmdTableDirect512 calculate CommandText by table name. All columns in the table are returned. It is only used with Recordset. Open or Requery. To use the Seek method, you must use adCmdTableDirect to open Recordset.

This value cannot be combined with the value adAsyncExecute of ExecuteOptionEnum.

This parameter adAsyncFetch is generally used for control.

. Properties ("InitalFetchSize") = 50

For more information, see the development of Visual Basic distributed applications in MSCE.

For example, Vb6.0 code:

DimAdoRsasADODB. Recordset

SetAdoRs = newADODB. Recordset

WithAdoRs

. CursorLocation = adUseClient

. Properties ("InitialFetchSize") = 50

. OpenmstrSQL, AdoCn, adOpenStatic, adLockOptimistic, adAsyncFetch

If. BOF = FalseOr. EOF = FalseThen

'--------------

Else

Endif

EndWith

Summary: many netizens have asked questions about the loading of large numbers. Now, this method can return data quickly. Generally, 1 million of data is required. The first 50 data records only require 5 ~ It will be returned in 6 seconds! Note the following:

1. If the returned data volume is too large and the data needs to be canceled in the middle, you must use AdoCn. Cancel to Cancel the query. Otherwise, the data will continue to be returned.

2. If the data volume is too large, the release of the record set may be faulty. If the data volume is between MB and MB ~ At MB, setadors = nothing will not release the cache quickly. I hope other netizens can provide their own opinions.

3. When there is a large amount of data, the C/S development provides a combination of page flip/GRID scroll bars, which is extremely convenient for users. Some netizens provide stored procedures for implementation. In the development process, I used paging controls and asynchronously loaded data sources to achieve good data browsing.

Development Environment: VB6.0 MSSQLServer2K WindowsADS2K.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.