ADO Programming Applications (1)

Source: Internet
Author: User
ADO (ActiveX Data Objects) is a component-based database programming interface, which is a COM component system independent of programming languages. This paper mainly introduces the techniques of ADO programming and the mode of ADO programming under VC, and discusses the C + + extensions briefly, hoping to have some help to the ADO developers. Because ADO is a programming language-independent COM component system, the main points discussed here apply to all programming languages and programming environments, such as VB, VBScript, VC, Java, and so on.
Programming skills
1. Explicitly defining an object type
In fact, this rule applies not only to ADO programming, but also to other programming related to COM objects. Because if the variable type is defined at the outset, the compiler can know the type of the variable at compile time, and the compiler is actually using the vtable offset to get the address of the method contained in the specific COM object (this is similar to the way the address of the virtual function in C + + is obtained) , but if you do not specify a variable type at the outset, such as simply using the following statement:
DIM Mycon as Object
Or is:
DIM Mycon
In this way, the compiler can not get the type of the variable at compile time, and can only dynamically get the information of the method (by using the Invoke method of the interface IDispatch), so as to get the address of the method and the related variables, it needs to make two calls internally. Will undoubtedly reduce the speed of the program running.
2. Binding columns to specific Field objects
By establishing a reference to a Field object at the beginning of the program, you can avoid increasing the overhead of the system by looking in the Recordset::fields after each record is obtained.
For example, you can use the code that looks like this:
Private Sub Tblbrowse_click ()
Dim Fld1 as ADODB. Field
Dim Fld2 as ADODB. Field
Dim rs as ADODB. Recordset
Set Rs=g_cn.execute (...)
' G_CN is a global object adodb.connection
Set fld1 = Rs. Fields ("id") ' Datasheet ' field
Set fld2 = Rs. Fields ("name") ' Data table ' field
If Rs. BOF = False Then
While Rs. BOF = False
Debug.Print Fld1. Value
Debug.Print Fld2. Value
Rs. MoveNext
Wend
End If
Rs. Close
End Sub
3. Data updates with SQL statements and stored procedures
Although it is convenient to use a Recordset object to update data, it is expensive, and the query set returned through the data source object contains not only the data but also the metadata (metadata), which in some cases may be larger than the data itself, Therefore, it is best to use SQL statements to update data. There is also the need to use stored procedures rather than a single SQL statement to get information. Because the stored procedures are executed on the server side, only the results are returned to the client, which reduces the cost of data interaction on the one hand, making the system easier to maintain and maintaining data consistency.

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.