




全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
VC database with ADO access to all Raiders1, ADO OverviewADO is Microsoft for the latest and most powerful data access paradigm designed OLE DB is an easy to use application layer interfaces. ADO allows you to write applications through OLE. DB provider to access and manipulate the data in the database server. ADO The main advantage is ease of use, speed, memory and disk less expenditure remains small. ADO in critical applications using the least network traffic, and front-end and data sources used the least number of layers, all of which are to provide a lightweight, high-performance interface. Is called ADO, is a familiar metaphor, OLE Automation interface.OLE DB is a set of Component Object Model (COM) interface, a new database low-level interface that encapsulates the ODBC functions, and in a uniform way to access information stored in different data sources. OLE DB is Microsoft UDA (Universal Data Access) technology base strategy. OLE DB data source provided for any high-performance access to these data sources including relational and non-relational databases, e-mail and file systems, text and graphics, custom business objects, and more. In other words, OLE DB is not limited to ISAM, Jet and even relational data source, it can handle any type of data, regardless of their format and storage methods. In practice, this diversity means to access resides in Excel spreadsheets, text files, e-mail / directory service or e-mail server, such as Microsoft Exchange in the data. However, OLE DB application programming interface is intended to provide the best variety of application functions, it does not meet the requirements of simplicity. You need to be an API to connect applications and OLE DB bridge, which is ActiveX Data Objects (ADO).Second, the use of VC ADO (developed as follows:)1, the introduction of ADO libraryUse ADO in the works before the stdafx.h header file # import symbols with the introduction of direct introduction of ADO libraries to enable the compiler to compile correctly. Code is as follows:With the introduction of ADO library files # import# Import c: program filescommon filessystemadomsado15.dll no_namespaces rename (EOF adoEOF )This line statement used in the project statement ADO, but ADO does not use the name space, and in order to avoid constant conflict, the constant EOF renamed adoEOF. Now no need to add another header file, you can use ADO interface to the.2, initialize OLE / COM library environmentImportant to note that, ADO COM library is a set of dynamic libraries, which means that the application before calling the ADO, you must initialize the OLE / COM library environment. In the MFC application, where a better approach is the applications InitInstance member function of the main class is initialized OLE / COM library environment.BOOL CMyAdoTestApp: InitInstance ()(if (! AfxOleInit ()/ initialize the COM library which is(AfxMessageBox (OLE Initialization Error!);return FALSE;). .)3, ADO Interface DescriptionADO library consists of three basic interfaces: _ConnectionPtr interfaces, _CommandPtr interface and _RecordsetPtr interfaces._ConnectionPtr Interface to return a record set or a null pointer. Often use it to create a data connection or perform a non-SQL statement that returns no results, such as a stored procedure. Use _ConnectionPtr Interface returns a recordset is not a good use. To return records for the operation is usually achieved with _RecordserPtr. The use of _ConnectionPtr operation to obtain a number of records may traverse all the records, but does not need to use _RecordserPtr._CommandPtr Interface returns a recordset. It provides a simple way to implement a stored procedure that returns a recordset and SQL statements. Using _CommandPtr interface, you can use the global _ConnectionPtr interface can also be used directly in the _CommandPtr interfaces in connection string. If you only implement one or more data access operation, which is a better choice. But if you want frequent access to the database, and to return many records set, then you should use the global _ConnectionPtr interface to create a data connection, and then use _CommandPtr interface to execute stored procedures and SQL statements._RecordsetPtr Is a recordset object. Compared with the above two objects, it provides a record set more control features, such as record locking, cursor control. Interface with _CommandPtr as it does not necessarily have to use an already created data connection, you can connect using a connection string instead of a pointer member variable assigned to _RecordsetPtr the connection, let it create a data connection. If you want to use multiple record sets, the best method is the same as with the Command object has already created a data connection using the global _ConnectionPtr Interface, And then use _RecordsetPtr SQL statement stored procedures and implementation.4, using _ConnectionPtr Interface_ConnectionPtr Is primarily a connection interface, made with the database. Its own direct connection string can be written, you can also point to an ODBC DSN._ConnectionPtr PConn;if (FAILED (pConn.CreateInstance (ADODB.Connection)(AfxMessageBox (Create Instance failed!);return;)CString strSRC;strSRC = Driver = SQL Server; Server =;strSRC + = suppersoft;strSRC + = ; Database =;strSRC + = mydb;strSRC + = ; UID = SA; PWD =;CString strSQL = Insert into student (no, name, sex, address) values (3,aaa, male, beijing);_variant_t varSRC (strSRC);_variant_t varSQL (strSQL);_bstr_t bstrSRC (strSRC);if (FAILED (pConn- Open (bstrSRC ,- 1)(AfxMessageBox (Can not open Database!);pConn.Release ();return;)COleVariant vtOptional (long) DISP_E_PARAMNOTFOUND, VT_ERROR);pConn- Execute (_bstr_t (strSQL), & vtOptional, -1);pConn.Release ();AfxMessageBox (ok!);5, using _RecordsetPtr interface (to connect to SQL Server as an example)_RecordsetPtr PPtr;if (FAILED (pPtr.CreateInstance (ADODB.Recordset)(AfxMessageBox (Create Instance failed!);return FALSE;)CString strSRC;strSRC = Driver = SQL Server; Server =;strSRC + = 210.46.141.145;strSRC + = ; Database =;strSRC + = mydb;strSRC + = ; UID = sa; PWD =;strSRC + = sa;CString strSQL = select id, name, gender, address from personal;_variant_t varSRC (strSRC);_variant_t varSQL (strSQL);if (FAILED (pPtr- Open (varSQL, varSRC, adOpenStatic, adLockOptimistic, adCmdText)(AfxMessageBox (Open table failed!);pPtr.Release ();return FALSE;)while (! pPtr- GetadoEOF ()(_variant_t varNo;_variant_t varName;_variant_t varSex;_variant_t varAddress;varNo = pPtr- GetCollect (id);varName = pPtr- GetCollect (name);varSex = pPtr- GetCollect (gender);varAddress = pPtr- GetCollect (address);CString strNo = (char *) _bstr_t (varNo);CString strName = (char *) _bstr_t (varName);CString strSex = (char *) _bstr_t (varSex);CString strAddress = (char *) _bstr_t (varAddress);strNo.TrimRight ();strName.TrimRight ();strSex.TrimRight ();strAddress.TrimRight ();int nCount = m_list.GetItemCount ();int nItem = m_list.InsertItem (nCount, _T ();m_list.SetItemText (nItem, 0, strNo);m_list.SetItemText (nItem, 1, strName);m_list.SetItemText (nItem, 2, strSex);m_list.SetItemText (nItem, 3, strAddress);pPtr- MoveNext ();)pPtr- Close ();pPtr.Release ();6, using _CommandPtr Interface_CommandPtr Returns a Recordset object interfaces, and provides more control recordset, the following code sample using _CommandPtr interface methods:Code: access to data using _CommandPtr Interface_CommandPtr PCommand;_RecordsetPtr PRs;pCommand.CreateInstance (_uuidof (Command);pCommand- ActiveConnection = pConn;pCommand- CommandText = select backup bin bin_old conf config crawler.tar.gz crawler_bin.tar.gz data eshow eshow_sitemap.html generate.sh google.html go
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 绿色建材在建筑行业中的应用前景与项目申请报告
- 三年级数学计算题专项练习及答案集锦
- 2025年电商绿色物流行业绿色物流企业竞争力提升路径与实践研究报告
- 年产21500吨自动化封箱设备胶带项目可行性研究报告
- 奥尔夫培训理论知识课件
- 二零二五年度乡村旅游用地承包合同范本:民宿项目合作协议
- 2025版隔层施工与室内装修一体化合同范本
- 二零二五版高端食品储藏室租赁及冷链服务协议
- 2025版影视版权转让居间代理合同
- 2025版新能源储能技术研发与合作协议执行步骤
- 2025年西藏自治区事业单位招聘考试教师招聘体育学科专业知识试卷(模拟试题)
- 先天性甲状腺功能减退症诊治指南解读课件
- 2025至2030中国裸眼3D行业产业运行态势及投资规划深度研究报告
- 检修安全监护管理制度
- 产科工作管理制度
- 初中历史教师业务考试试题及答案
- 导尿管相关尿路感染预防与控制试题(附答案)
- 中医烧伤课件
- 2025-2030中国水下混凝土行业市场发展趋势与前景展望战略研究报告
- GB/T 30134-2025冷库管理规范
- 2025年心理咨询师基础理论知识测试卷:心理咨询心理学理论体系试题
评论
0/150
提交评论