Summary Visual C active data object
Screen capture of the program: Summary: This paper briefly introduces Microsoft's Activity Data Object (ADO) model, combined with instances to use the ADO manipulation database in the Visual C environment, analyze the characteristics of ADO and open database connections (ODBC) Differences and application prospects. Left: ADO Object Model Keywords: Active Data Object Database Visual C 1 ADO is a component of the Microsoft's entire COM strategy system (ADO) is a set of COM components provided by Microsoft. ADO is built on the COM architecture advocated by Microsoft, and all of its interfaces are automated interfaces, so the ADO can be accessed through the interface in the development language of C , VisualBasic, Delphi and other support COM. ADO implements data that can access relational databases, text files, non-relational databases, index servers, and active directory services, etc. in the same way by using OLE DB, and expand the range of data sources used in applications, thus The preferred choice for accessing the data source components in the entire COM strategy system is an alternative product of ODBC. 2 ADO object model Compared to Microsoft's other data access models DAO and RDO, the ADO object model is very refined, consisting of three main objects Connection, Command, Recordset, and several auxiliary objects, which are shown in the figure. The Connection object provides the association between the OLE DB data source and the dialog object, which handles the authentication of the user's identity through the user name and password, and provides support for transaction processing; it also provides execution method to simplify the connection and data search of the data source. Process. The Command object encapsulates the data source that can be interpreted, which can be any content that the SQL command, the stored procedure, or the underlying data source can be understood. Record Set is used to represent the table data returned from the data source, which encapsulates the navigation, record update, record deletion, and new records of the record collection, and provides a bulk update record. Other auxiliary objects provide columns from encapsulation ADO errors, package command parameters, and packaging records. 3 ADO Characteristics (1) Since many underlying work is encapsulated, ADO is used almost as convenient to use ODBC. (2) ADO is not only the main function of ODBC, but also has a large number of data sources for ADO applicable. (3) When defining the ADO recordset and the database table field binding class, the field variables, status variables are required, and the order must be the same. This is more complex than using ODBC in FMC. However, in the macro bound to the Database field and the ADO record set field variable, the data type provided by the ADO is much more than the RFX in the FMC (such as the datetime type, which can only be converted to a CString type) in the ODBC). (4) ADO allows multiple Record Set instances under the same Connection instance. (5) ADO allows for batch update (Update Batch method), which will greatly reduce the network burden and improve database processing efficiency. 4 ADO uses the use of Microsoft to operate the SQL Server database using the ADO interface in Visual C with ADO2 provided in MicrSoft Studio 6. Using ADO in compilation advanced languages, it is difficult to use ADO in some scripting languages (such as Visual Basic Scropt and JavaScript).
The basic steps of using ADO's Connection objects and its Record Set objects are given under a Visual C : (1) Introducing Ado2 Components: #import "c: adomsado15.dll" NO_NAMESPACE RENAME ("EOF", "ENDOFFILE ") (2) Define the derived class of CADORECORDBINDING, used for the interaction of the program and database table field, which can be found in ICRSINT.H. Example: Class CintLive: Public Cadorecordbinding {public: dbtimestamp m_datetime; // Defines the ADO record set field variable (corresponding to the database table field) long m_key; long m_value; long m_quality; word m_stsdatetime; // Define ADO record set status Variable Word m_stskey; WORD m_stsvalue; WORD m_stsquality; BEGIN_ADO_BINDING (CIntlive) // record database fields set ADO field variable bindings ADO_VARIABLE_LENGTH_ENTRY2 (1, adDBTimeStamp, m_datetime, sizeof (m_datetime), m_stsdatetime, true) ADO_NUMERIC_ENTRY (2, adInteger, m_key, 10,0, m_stskey, true) ADO_NUMERIC_ENTRY (3, adInteger, m_value, 10,0, m_stsvalue, true) ADO_NUMERIC_ENTRY (4, adInteger, m_quality, 10,0, m_stsquality, true) END_ADO_BINDING ()}; (3) call CoInitialize Initialization COM :: Coinitialize (NULL); (4) Declares the ADO's Connection object pointer and the Recordset object pointer and initialize. (Type name is defined in msado15.dll) example: _ConnectionPtr PConnection1 = null; _recordsetptr rstado1 = null; (5) Define instances of Cadorecordbinding derived class and its Bind interface pointer. Example: cintlive m_intdata; iporecordbinding * RstadObind1 = null; (6) Generates an instance of the Connection object instance and the Record Set object. Example: PConnection1.createInstance (_UUIDOF (Connection)); RSTADO1.CREATEINSTANCE (__ uuidof (recordset)); (7) Connect to the database and open the Record set object, where the Open function's parameters can be found in Microsoft MSDN ADO corresponding objects Basic description of the parameters.