⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vcg22.htm

📁 Visual C++与数据库的连接经典实例
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<HTML>

<HEAD>

<TITLE>vcg22.htm </TITLE>

<LINK REL="ToC" HREF="index-1.htm" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/index.htm">

<LINK REL="Index" HREF="htindex.htm" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/htindex.htm">

<LINK REL="Next" HREF="vcg23.htm" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/vcg23.htm">

<LINK REL="Previous" HREF="vcgp6.htm" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/vcgp6.htm"></HEAD>

<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080">

<A NAME="I0"></A><P ALIGN=CENTER>

<A HREF="vcgp6.htm" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/vcgp6.htm" TARGET="_self"><IMG SRC="blanprev.gif" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/blanprev.gif" WIDTH = 37 HEIGHT = 37 BORDER = 0 ALT="Previous Page"></A>

<A HREF="index-1.htm" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/index.htm" TARGET="_self"><IMG SRC="blantoc.gif" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/blantoc.gif" WIDTH = 37 HEIGHT = 37 BORDER = 0 ALT="TOC"></A>

<A HREF="vcg23.htm" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/vcg23.htm" TARGET="_self"><IMG SRC="blannext.gif" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/blannext.gif" WIDTH = 37 HEIGHT = 37 BORDER = 0 ALT="Next Page"></A>


<HR ALIGN=CENTER>

<P>

<UL>

<UL>

<UL>

<LI>

<A HREF="#E68E113" >Preparing a Data Dictionary</A>

<UL>

<LI>

<A HREF="#E69E273" >Writing a Visual C++ Application to Create a Data Dictionary</A>

<UL>

<LI>

<A HREF="#E70E119" >Adding CTL3DV2V2.DLL to Create Three-Dimensional, Shaded Dialog Boxes</A>

<LI>

<A HREF="#E70E120" >Running DOCDB</A>

<LI>

<A HREF="#E70E121" >Altering the Visual C++ Code in DOCDB</A>

<LI>

<A HREF="#E70E122" >Exporting Access's Database Documentor Output</A></UL>

<LI>

<A HREF="#E69E274" >Using Access's Database Documentor to Document Databases</A>

<LI>

<A HREF="#E69E275" >Documenting Databases Created with CASE Tools</A>

<LI>

<A HREF="#E69E276" >Using Total Access to Create a Data Dictionary</A></UL>

<LI>

<A HREF="#E68E114" >Creating Manuals for Your Database Applications</A>

<UL>

<LI>

<A HREF="#E69E277" >The Structure of User Manuals</A>

<UL>

<LI>

<A HREF="#E70E123" >Front Matter</A>

<LI>

<A HREF="#E70E124" >Text</A>

<LI>

<A HREF="#E70E125" >Back Matter</A></UL>

<LI>

<A HREF="#E69E278" >Using Doc-To-Help to Create Convertible Manuals</A></UL>

<LI>

<A HREF="#E68E115" >Summary</A></UL></UL></UL>

<HR ALIGN=CENTER>

<A NAME="E66E55"></A>

<H1 ALIGN=CENTER>

<CENTER>

<FONT SIZE=6 COLOR="#FF0000"><B>- 22 -</B>

<BR><B>Documenting Your Database Applications</B></FONT></CENTER></H1>

<BR>

<P>A database application isn't complete until you've prepared professional-grade documentation for each element of the application. The &quot;Visual C++&quot; qualifier is missing from the preceding truism of professional database developers because this statement applies to all database applications created with any front-end development tool or programming language. Visual C++ doesn't provide any documentation tools specific to database applications, and what <I>is</I> provided (help file shells and source comments) is rather basic.

<BR>

<P>This chapter describes the following three basic documentation elements for all database applications:

<BR>

<UL>

<LI>Data dictionaries that fully describe the tables of the database(s) used by the application and each field of the tables that the application reads or updates. Data dictionaries also specify primary and foreign key fields and relations between tables, as well as security restrictions that apply to the tables. (Some RDBMSs let you enforce security provisions at the field level.) Referential and domain integrity rules that are enforced at the database and table levels, respectively, or that must be incorporated into every application that updates the tables, are also included in the data dictionary.

<BR>

<BR>

<LI>Code and form printouts that include sufficient commentary to make the source code comprehensible to others who need to maintain the application by revising the code and/or the form design. A programmer should be able to totally reconstruct the original application from this documentation element. Code and form printouts also contain version control information that identifies modifications made to the original code, who made the revisions, the purpose of the revision, and when the revision was made (including the version number to which the revision applies). A flow diagram of the application also aids others who need to understand the concept and construction of your database front end.

<BR>

<BR>

<LI>User manuals that provide instructions for installing and using the application the way you intended. Regardless of how intuitive your application is or how complete its built-in help system is, a printed user manual should be provided as a distributable item of any database application. Although users seldom refer to printed manuals (except as a last resort), your online help system can be created from the user manual if you have WexTech Systems' Doc-To-Help application, which is described near the end of this chapter. Using Doc-To-Help to create Windows help files is covered in Chapter 23, &quot;Creating Help Files for Database Applications.&quot;

<BR>

<BR>

</UL>

<P>The major sections of this chapter deal sequentially with each of the documentation elements in the preceding list.

<BR>

<BR>

<A NAME="E68E113"></A>

<H3 ALIGN=CENTER>

<CENTER>

<FONT SIZE=5 COLOR="#FF0000"><B>Preparing a Data Dictionary</B></FONT></CENTER></H3>

<BR>

<P>Data dictionaries are the most important element of database documentation. If you use a product such as Asymetrix's InfoModeler, the process of documenting the database will be a bit easier. InfoModeler provides a vast array of printed reports, tables, and charts to document your database. This chapter describes some of InfoModeler's capabilities, as well as other database documentation techniques.

<BR>

<P>At the very least, data dictionaries should include the following components:

<BR>

<UL>

<LI>A narrative description of the purpose and overall structure of the database.

<BR>

<BR>

<LI>A detailed description of each table in the database, usually in tabular format.

<BR>

<BR>

<LI>The name of each field of the tables in the database, together with the field data type and field size (if not determined by the field data type).

<BR>

<BR>

<LI>Entries that identify primary and foreign key fields in each table.

<BR>

<BR>

<LI>A list of constraints (validation rules) for field values that are used to maintain domain integrity and an indication of whether these constraints are enforced at the table level by the RDBMS or must be maintained by application code.

<BR>

<BR>

<LI>A graphical or tabular description of the relations between the key fields of the tables and an indication of whether the relational integrity is enforced by the RDBMS or by applications.

<BR>

<BR>

<LI>A list of stored procedures and triggers, including the source code for the stored procedures and triggers, if the RDBMS supports these features.

<BR>

<BR>

</UL>

<P>The following sections describe writing your own Visual C++ application to create a data dictionary, using a CASE tool to create an Access database (including a data dictionary for the database), obtaining table data from Access's Database Documentor (described later), and using a commercial Access documentation tool such as InfoModeler to create data dictionaries for Access databases. The emphasis of this chapter is on the .MDB database format, because the Access database structure is the most likely to be used in the majority of new Visual C++ applications.

<BR>

<BR>

<A NAME="E69E273"></A>

<H4 ALIGN=CENTER>

<CENTER>

<FONT SIZE=4 COLOR="#FF0000"><B>Writing a Visual C++ Application to Create a Data Dictionary</B></FONT></CENTER></H4>

<BR>

<P>It's relatively easy to write a Visual C++ database application to create a fully formatted data dictionary as a text file that you can import into Word for Windows or any another word processing or spreadsheet application. It's an even simpler process if you've created (or have access to the source code for) a data dictionary generator for Access databases that relies primarily on C or C++ code.

<BR>

<P>DOCDB, the sample data dictionary application that is described in the following sections, is based on the ODBC access routines described in Chapter 7, &quot;Using the Open Database Connectivity API.&quot;

<BR>

<P>DOCDB is a simple form-view Visual C++ program. It was originally developed with Visual C++ 1.5 and was then recompiled as a 32-bit application using Visual C++ 4. It's not uncommon to have to convert 16-bit applications to 32-bit when you're converting to either Visual C++ 2.x or 4. The 32-bit version of DOCDB is available on the CD that comes with this book.

<BR>

<P>DOCDB performs a simple task: It provides all the information that ODBC can provide about the columns in a specified table. This information is presented in a form. It would be easy to add report printing capabilities to DOCDB, and even to add the capability to report on all tables in a given database when you create a printed report. However, printed reports would be secondary to adding additional functionality to DOCDB to enhance DOCDB's retrieval of information about a database.

<BR>

<P>DOCDB is a simple program. It was created using AppWizard, with only two changes to the default &quot;stock&quot; program: It is a Single Document Interface (SDI) program with a CFormView view class. Neither database nor OLE support has been added to DOCDB, because these features weren't needed.

<BR>

<P>After DOCDB has been created, the first step is to incorporate the ODBC routines. Adding this support is detailed in Chapter 3, &quot;Using Visual C++ Data Access Functions,&quot; and it consists of these steps:

<BR>

<OL>

<LI>Copy the ODBC helper routines (ODBC1.C, ODBCMISC.H, ODBC2.CPP, ODBCTABL.CPP, and ODBCINFO.CPP) to the \DOCDB directory.

<BR>

<BR>

<LI>Edit the DOCDB project and add the ODBC helper source files (the .CPP and .C files from step 1) to the project.

<BR>

<BR>

<LI>Edit the ODBC C/C++ source files and add this DOCDB header file #include statement:

<BR>

<BR>

<BR>

<PRE>

<FONT COLOR="#000080">#include &quot;odbcmisc.h&quot;</FONT></PRE>

<LI>Copy the dialog box templates from ODBC.RC to the DOCDB resources.

<BR>

<BR>

<LI>Add the ODBC library to the ODCDB library list.

<BR>

<BR>

</OL>

<P>You can refer to Chapter 3 for more-detailed steps if you need to.

<BR>

<P>After you've followed the preceding steps, you can do a test compile of the ODCDB project. If the compilation succeeds without errors, you can continue to create the DOCDB program.

<BR>

<P>The next step is to use the resource editor to add the controls to the DOCDB main dialog box. Figure 22.1 shows this dialog box, including the dialog control IDs.

<BR>

<P><B><A HREF="22vcg01.gif" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/22vcg01.gif">Figure 22.1. DOCDB's main window dialog box.</A></B>

<BR>

<BLOCKQUOTE>

<BLOCKQUOTE>

<HR ALIGN=CENTER>

<BR>

<NOTE><B>NOTE</B>

<BR>

<BR>All unmarked controls in Figure 22.1 are IDC_STATIC.</NOTE>

<BR>

<HR ALIGN=CENTER>

</BLOCKQUOTE></BLOCKQUOTE>

<P>Each control in DOCDB must be bound to a variable, with the exception of the New Database button, which has an attached function, and the Column Name combo box, which calls a function whenever the current selection (the column in the table) has changed. The dialog is managed by the CDocdbView class (found in DOCDBVW.CPP).

<BR>

<P>After the dialog box has been created, in Visual C++ use ClassWizard to bind variables to the controls, as shown in Table 22.1.

<BR>

<BR>

<P ALIGN=CENTER>

<CENTER>

<FONT COLOR="#000080"><B>Table 22.1. Variable names for DOCDB's controls.</B></FONT></CENTER>

<BR>



<CENTER><TABLE  BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 CELLPADDING=3 >

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

<I>Control</I>

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

<I>Variable Name</I>

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

<I>Variable Type</I>

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

<I>Description</I>

</FONT>

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

IDC_COLUMN

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

m_ColumnList

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

CComboBox

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

The list of all the columns in the selected table is stored here. This is both an input and an output control.

</FONT>

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

IDC_CONNECT

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

m_Connect

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

CString

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

This output control shows the current connect string.

</FONT>

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

IDC_DATASOURCE

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

m_DataSource

</FONT>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -