ADO Uncover 1

Source: Internet
Author: User
Tags dsn odbc

Overview

ADO objects can be used on all platforms that support COM and OLE, such as Vb,vc++,vbscrip,java and so on. Includes the following seven objects:

Connection

Command

Parameter

Recordset

Field

Property

Error

and four collections:

Fields

Properties

Parameters

Errors

The core of ADO is the Connection,recordset and command objects. First use connection to establish a connection with the server, and then use the command object to execute commands, such as queries, updates, and so on. Use the Recordset object to manipulate and view query results. It's so simple.

Of course, like its name, the Parameters collection and the Parameters object are parameter information for the command object. The error collection and errors object in connection provide the wrong information after an error has occurred. Once the query results are obtained, the field collection and Field objects can be used through the Recordset object, which provides information about the related fields.

Long March first step

Everything starts with the connection. The Connection object includes the initial and connection mechanisms, as well as executing queries, using transactions, and so on. By default, the ODBC-driven (MSDASQL) provided by MS is used. To use other vendor's dongdong, you need to set it in the Provider property. With ODBC drivers, ADO can connect to any ODBC-enabled database service: An ODBC data source or an externally specified data source information (usually a DSN-less connection).

Before you start the connection, set the connection word, default database, and connection properties. The Open method in the object is used to establish the connection. Use the Execute method to execute a query. Transaction processing can also be supported in connection objects: through Begintrans,committrans, and RollbackTrans methods.

Here is an example of connecting to SQL Server using ODBC drivers (simple!). ):

Dim Cn as New ADODB. Connection

TimeOut? setting is related to the network environment

Cn.connectiontimeout = 100

DSN Connection

#Cn. Open pubs, SA

DSN-free connection to SQL Server

Cn.open Driver={sql Server}; Server=server1; Uid=sa; pwd=;D Atabase=pubs

Cn.close

The following is an example of using transactions:

Dim Cn as New ADODB. Connection

Dim rs as New ADODB. Recordset

Open connection

Cn.open pubs, SA

Open the Titles table

Rs. Open SELECT * FROM titles, Cn, adOpenDynamic, adlockpessimistic

Cn.begintrans

Make changes

Cn.committrans

or regret it:

cn. RollbackTrans

Cn.close

After establishing the connection, everything will be OK. The command object can be used to achieve full control of the database.

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.