Microsoft KB Archive/229029

= SAMPLE: AdoDataGrid.exe Demonstrates How to Use ADO with DataGrid Control Using Visual C++ =

Article ID: 229029

Article Last Modified on 11/23/2006

-

APPLIES TO


 * Microsoft ActiveX Data Objects 2.0
 * Microsoft ActiveX Data Objects 2.1
 * Microsoft ActiveX Data Objects 2.5
 * Microsoft ActiveX Data Objects 2.6
 * Microsoft ActiveX Data Objects 2.7
 * Microsoft Visual C++ 6.0 Enterprise Edition

-



This article was previously published under Q229029



SUMMARY
The AdoDataGrid sample demonstrates the various uses and combinations of ADO objects, and shows how to use the ADO Recordset object to populate the Microsoft DataGrid control, which makes presenting data through ADO very easy in Visual C++.

The sample also shows how to get results (recordset) based on run-time queries and how to populate the DataGrid control with that recordset. This sample application also demonstrates how to use the OLE DB DataLink interface to build a connection string at run time.

NOTE: At the time this sample was developed, table names with spaces were not taken into consideration. For table names with spaces (for instance, "Order Details") or table names that are keywords (for instance, "Section"), this sample may give an error. To correct the problem, modify the code to enclose the table name with brackets ([]); for example, [Order Details].



MORE INFORMATION
The following files are available for download from the Microsoft Download Center:

AdoDataGrid.exe

Release Date: May-27-1999

For additional information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base:

119591 How to Obtain Microsoft Support Files from Online Services

Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help to prevent any unauthorized changes to the file.

Sample File Information
The AdoDataGrid sample is a FormView-based SDI MFC application. All the files are wizard-generated. After inserting the ActiveX object (Microsoft DataGrid control), the wizard will provide CColumn, CColumns, CDataFormatDisp, CDataGrid, COleFont, CPicture, CSelBookmarks, CSplit, CSplits, and CStdDataFormatsDisp classes in their respective files. No modification was made in DataGrid and its dependent files for this sample.

In this sample, code for manipulating ADO objects is located in AdoDataGridView.cpp. The #import statement for ADO is located in Stdafx.h.

There are three methods to use ADO with Visual C++. In this project, the #import method is used. For additional information about #import and other methods, please see the following article in the Microsoft Knowledge Base:

220152 Sample: ADOVC1 Simple ADO/VC++ Application

Brief Description of User Interface

 * BuildConnStr launches the OLE DB DataLink connection dialog box, which is a container for a connection string. You can manually type in the connection string in a given edit box.
 * Connect uses a connection string in the given edit box and connects to the data source. Upon connecting to the data source, Connect populates the list with all the tables available in the data source.
 * Get Tables populates the list of all tables. You can click any table and DataGrid will be populated with the rows from the table.
 * ReQuery regenerates results based on a user-typed query in the query edit box.
 * Disconnect disconnects from the Data source and clears out Datagrid. Notice that the user can still type in a connection string and query and get the resultset back by clicking ReQuery, because ReQuery creates an explicit connection to the DataSource.

NOTE: Datalink (OLE DB connection string building interface) was moved from Msdasc.dll to Oledb32.dll in MDAC 2.1. If you have MDAC version 2.1 or later installed on your machine, replace Msdasc.dll with Oledb32.dll in the #import statement in StdAfx.h.

For additional information about this problem, please see the following article in the Microsoft Knowledge Base:

225132 DataLink Type Library Moved from Msdasc.dll to Oledb32.dll

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Partner or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Partners, please visit the following Microsoft Web site:

https://partner.microsoft.com/global/30000104

For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:

http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS

