📄 right19-2.htm
字号:
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>第 19 章</title>
<base target="rbottom">
<style>
<!--
.右标题 { font-size: 10pt; color: #000080; text-indent: 0; margin: 0 }
.右内容 { font-size: 10pt; text-align: left; text-indent: 0; line-height: 100%; margin:
0 }
-->
</style>
</head>
<body>
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"><span style="position: absolute; left: 4; top: -8"><img border="0" src="1.gif" width="63" height="70"></span></p>
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
<p style="line-height: 100%; text-indent: 0; margin: 0" class="右标题" align="left">
<span style="background-color: #CCFF99">第 19 章</span><span style="background-color: #CCFF99">
</span>><span style="background-color: #CCFF99"> 第 2 节 </span>><span style="background-color: #CCFF99">
19.2 </span><span style="background-color: #CCFF99">ODBC数据库程序设计</span></p>
<hr color="#008000" size="1">
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">ODBC<font LANG="ZH-CN"><font FACE="??ì?,SimSun" LANG="ZH-CN">(</font>Open
Database Connectivity<font FACE="??ì?,SimSun" LANG="ZH-CN">,开放数据库互连)</font>建立了一组规范,并提供了一组对数据库访问的标准</font>API,<font LANG="ZH-CN">这些</font>API<font LANG="ZH-CN">利用</font>SQL<font LANG="ZH-CN">来完成其大部分任务。</font>ODBC<font LANG="ZH-CN">本身也提供了对</font>SQL<font LANG="ZH-CN">语言的支持,用户可以直接将</font>SQL<font LANG="ZH-CN">语句传送给</font>ODBC<font LANG="ZH-CN">。</font></font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">1.
<font LANG="ZH-CN">ODBC简介</font></font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2"><font LANG="ZH-CN">一个基于</font>ODBC<font LANG="ZH-CN">的应用程序对数据库的操作不依赖任何</font>DBMS<font LANG="ZH-CN">,不直接与</font>DBMS<font LANG="ZH-CN">打交道,所有的数据库操作由对应的</font>DBMS<font LANG="ZH-CN">的</font>ODBC<font LANG="ZH-CN">驱动程序完成。</font></font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2"><font LANG="ZH-CN">一个完整的</font>ODBC<font LANG="ZH-CN">由下列几个部件组成:</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2"><font LANG="ZH-CN">①
应用程序(</font>Application<font LANG="ZH-CN">)</font></font></p>
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2"><font LANG="ZH-CN">②
</font>ODBC<font LANG="ZH-CN">管理器(</font>Administrator<font LANG="ZH-CN">)</font></font></p>
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2"><font LANG="ZH-CN">③
驱动程序管理器(</font>Driver Manager<font LANG="ZH-CN">)</font></font></p>
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2"><font LANG="ZH-CN">④
</font>ODBC API</font></p>
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2"><font LANG="ZH-CN">⑤
</font>ODBC<font LANG="ZH-CN">驱动程序</font></font></p>
<font SIZE="3">
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font LANG="ZH-CN" size="2">⑥
数据源</font></p>
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2"><font LANG="ZH-CN">应用程序要访问一个数据库,首先必须用</font>ODBC<font LANG="ZH-CN">管理器注册一个数据源,建立起</font>ODBC<font LANG="ZH-CN">与具体数据库的联系。</font></font><font size="2"><font LANG="ZH-CN">在</font>ODBC<font LANG="ZH-CN">中,</font>ODBC
API<font LANG="ZH-CN">不能直接访问数据库,必须通过驱动程序管理器与数据库交换信息。</font></font></p>
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">2.
MFC<font LANG="ZH-CN">的</font>ODBC<font LANG="ZH-CN">类简介</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">MFC<font LANG="ZH-CN">的</font>ODBC<font LANG="ZH-CN">类主要包括:</font></font></p>
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2"><font LANG="ZH-CN">①
</font>CDatabase<font LANG="ZH-CN">类:</font><font LANG="ZH-CN">针对某个数据库,它负责连接数据源。</font></font></p>
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2"><font LANG="ZH-CN">②
</font>CRecordset<font LANG="ZH-CN">类:</font><font LANG="ZH-CN">针对数据源中的记录集,它负责对记录的操作。</font></font></p>
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2"><font LANG="ZH-CN">③
</font>CRecordView<font LANG="ZH-CN">类:负责界面。</font></font></p>
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2"><font LANG="ZH-CN">④
</font>CFieldExchange<font LANG="ZH-CN">类:负责</font>CRecordset<font LANG="ZH-CN">与数据源的数据交换。</font></font></p>
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2"><font LANG="ZH-CN">⑤
</font>CDBException<font LANG="ZH-CN">类:代表</font>ODBC<font LANG="ZH-CN">类产生的异常。</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">3.
CDatabase<font LANG="ZH-CN">类</font></font></p>
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2"><font LANG="ZH-CN">要建立与数据源的连接,首先应构造一个</font>CDatabase<font LANG="ZH-CN">对象,然后再调用</font>CDatabase<font LANG="ZH-CN">的</font>Open<font LANG="ZH-CN">成员函数。</font></font></p>
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">4.
CRecordset<font LANG="ZH-CN">类</font></font></p>
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2"><font LANG="ZH-CN">用户一般需要用</font>ClassWizard<font LANG="ZH-CN">创建一个</font>CRecordset<font LANG="ZH-CN">的派生类,</font>ClassWizard<font LANG="ZH-CN">可以为派生的记录集类创建一批数据成员,这些数据成员与记录的各字段相对应,被称为字段数据成员或域数据成员。记录集的建立实际上主要是一个查询过程,</font>SQL<font LANG="ZH-CN">的</font>SELECT<font LANG="ZH-CN">语句用来查询数据源。</font></font></p>
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">5.
CRecordView<font LANG="ZH-CN">类</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">CRecordView<font LANG="ZH-CN">提供了一个表单视图来显示当前记录。用户一般需要创建一个</font>CRecordView<font LANG="ZH-CN">的派生类并在其对应的对话框模板中加入控件。</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">6
<font LANG="ZH-CN">程序举例</font></font></p>
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2"><font LANG="ZH-CN"><a href="example19-1.htm" target="_blank">【例</a></font><a href="example19-1.htm" target="_blank">19-1<font LANG="ZH-CN">】</font></a><font LANG="ZH-CN">在</font>Access<font LANG="ZH-CN">中创建表,并存入文件</font>student.mdb<font LANG="ZH-CN">中。编写程序访问数据库,并能完成显示记录、添加记录、删除记录、修改记录和查找记录等操作。</font></font></p>
<font SIZE="3"></font>
<hr size="1" color="#008000">
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"> <span style="position: absolute; left: 32; top: 732"><a href="right19-1.htm" target="_self"><img border="0" src="rightd1.gif" width="113" height="70"></a></span>
<span style="position: absolute; left: 505; top: 736"><a href="right19-3.htm" target="_self"><img border="0" src="rightd2.gif" width="124" height="63"></a></span></p>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -