📄 vc++程序员如何阅读ado文档1.htm
字号:
<TD><A href="http://www.chinabyte.com/" target=_blank><FONT
color=#ffffff>chinabyte</FONT></A></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
<TABLE height=2 cellSpacing=0 cellPadding=0 width=775 border=0>
<TBODY>
<TR>
<TD width=37 bgColor=#ffffff></TD>
<TD width=1 bgColor=#ffffff></TD>
<TD width=33 bgColor=#7b91a9></TD>
<TD width=704 bgColor=#ffffff></TD></TR></TBODY></TABLE><IFRAME
src="VC++程序员如何阅读ADO文档1.files/f-dh.htm" frameBorder=0 width=775 scrolling=no
height=40></IFRAME>
<TABLE cellSpacing=0 cellPadding=0 width=775 bgColor=#7b91a9 border=0>
<TBODY>
<TR>
<TD width=8 height=1></TD>
<TD width=767 bgColor=#000000 height=1></TD></TR></TBODY></TABLE></DIV>
<TABLE cellSpacing=0 cellPadding=0 width=775 align=center bgColor=#f6f5f2
border=0>
<TBODY>
<TR>
<TD width=8 bgColor=#7b91a9></TD>
<TD width=1 bgColor=#000000></TD>
<TD width=766><IFRAME src="VC++程序员如何阅读ADO文档1.files/y-soft-column-1.htm"
frameBorder=0 width=766 scrolling=no
height=96></IFRAME></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width=775 bgColor=#ffffff border=0>
<TBODY>
<TR>
<TD width=8 bgColor=#7b91a9></TD>
<TD width=1 bgColor=#000000></TD>
<TD vAlign=top align=middle width=163><IMG
src="VC++程序员如何阅读ADO文档1.files/03-14.gif"></IMG>
<TABLE cellSpacing=0 cellPadding=0 width=151 border=0>
<TBODY>
<TR>
<TD width=1 bgColor=#698096></TD>
<TD width=149>
<TABLE cellSpacing=0 cellPadding=5 width=149 border=0>
<FORM name=sform onsubmit="return check()"
action=http://211.167.73.227/cgi-bin/wstsearch method=get
target=_blank>
<TBODY>
<TR>
<TD vAlign=bottom align=right width=100>
<SCRIPT language=JavaScript>function check(){ if(sform.iftitle.value==1) { sform.title.value=sform.query.value; }else { sform.content.value=sform.query.value; }}</SCRIPT>
<INPUT type=hidden value=wst name=tn></INPUT><INPUT
type=hidden value=1 name=relative></INPUT><INPUT type=hidden
value=1 name=smart_abstract></INPUT><INPUT type=hidden
value="Last-Modified DESC" name=sort></INPUT><INPUT
type=hidden name=title></INPUT><INPUT type=hidden
name=content></INPUT><INPUT type=hidden value=10
name=rn></INPUT><INPUT type=hidden value=1
name=thesaurus></INPUT><INPUT type=hidden
name=ch_id></INPUT><INPUT maxLength=120 size=12
name=query></INPUT><SELECT name=iftitle><OPTION value=0
selected checked="yes">全文检索</OPTION><OPTION
value=1>标题检索</OPTION></SELECT></TD>
<TD width=49><INPUT type=image alt=开始检索
src="VC++程序员如何阅读ADO文档1.files/03-04.gif" align=bottom border=0
name=image></INPUT></TD></TR></FORM></TBODY></TABLE></TD>
<TD width=1 bgColor=#698096></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width=151 border=0>
<TBODY>
<TR>
<TD bgColor=#698096 height=1></TD></TR></TBODY></TABLE><IMG height=3
src="VC++程序员如何阅读ADO文档1.files/03-13.gif" width=3 align=top></IMG></TD>
<TD width=10 bgColor=#f7f7f7></TD>
<TD vAlign=top width=464 bgColor=#f7f7f7>您的位置是: <A
href="http://www.yesky.com/SoftChannel/72339069014638592/index.shtml">软件</A>
> <A
href="http://www.yesky.com/SoftChannel/72342367549521920/index.shtml">开发者网络</A>
> <A
href="http://www.yesky.com/SoftChannel/72342371844489216/index.shtml">开发工具</A>
> <A
href="http://www.yesky.com/SoftChannel/72342371928375296/index.shtml">开发专栏</A>
> <A
href="http://www.yesky.com/SoftChannel/72342371928702976/index.shtml">VC专栏</A>
> 正文 <IMG height=10 src="VC++程序员如何阅读ADO文档1.files/03-13.gif"
width=10></IMG><A href="http://www.cseek.com/">查cseek报价</A><BR><BR><FONT
class=f22><B>VC++程序员如何阅读ADO文档</B></FONT><BR>2003-10-21<FONT
color=#f7f7f7>■</FONT>CANDY<FONT color=#f7f7f7>■</FONT>论坛</TD>
<TD vAlign=bottom width=130 bgColor=#f7f7f7>
<TABLE cellSpacing=0 cellPadding=0 width=130 border=0>
<TBODY>
<TR>
<TD align=right width=96><A href="javascript:sendemail()"><FONT
color=#ff5d00>我对此感兴趣</FONT></A></TD>
<TD width=34><IMG height=22 src="VC++程序员如何阅读ADO文档1.files/03-17.gif"
width=22></IMG></TD></TR>
<TR>
<TD align=right width=96><A
href="http://211.167.73.173/mail/index.htm"><FONT
color=#8c8a8a>订阅电子杂志</FONT></A></TD>
<TD width=34><IMG height=22 src="VC++程序员如何阅读ADO文档1.files/03-18.gif"
width=19></IMG></TD></TR>
<TR>
<TD align=right width=96>
<SCRIPT language=JavaScript>function bbs(){ OpenWindow = window.open('http://bbs.yesky.com/yeskybbs.asp?body=VC++程序员如何阅读ADO文档&bbsid=9&url=http://www.yesky.com/SoftChannel/72342371928702976/20031021/1737617.shtml&aid=1737617','bbs','')}</SCRIPT>
<A href="javascript:bbs()"><FONT color=#8c8a8a>发表评论</FONT></A></TD>
<TD width=34><IMG height=22 src="VC++程序员如何阅读ADO文档1.files/03-19.gif"
width=21></IMG></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width=775 bgColor=#ffffff border=0>
<TBODY>
<TR>
<TD width=8 bgColor=#7b91a9></TD>
<TD width=1 bgColor=#000000></TD>
<TD vAlign=top align=middle width=163>
<TABLE cellSpacing=0 cellPadding=0 width=163
background=VC++程序员如何阅读ADO文档1.files/03-20.gif border=0>
<TBODY>
<TR>
<TD width=20></TD>
<TD width=143><FONT
color=#ffffff>advertisement</FONT></TD></TR></TBODY></TABLE><IFRAME
src="VC++程序员如何阅读ADO文档1.files/y-software-skyscraper.htm" frameBorder=0
width=160 scrolling=no height=500></IFRAME>
<TABLE cellSpacing=0 cellPadding=0 width=163
background=VC++程序员如何阅读ADO文档1.files/03-20.gif border=0>
<TBODY>
<TR>
<TD width=20></TD>
<TD width=143 height=28><FONT
color=#ffffff>热点推荐</FONT></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width=155 border=0>
<TBODY>
<TR>
<TD><A
href="http://www.yesky.com/SoftChannel/72347899534508032/20031019/1737162.shtml"
target=_blank>全能网管之网吧常用Windows下工具</A><BR><A
href="http://www.yesky.com/SoftChannel/72347882287529984/20031018/1737119.shtml"
target=_blank>ACDSee6.0试用手记</A><BR><A
href="http://www.yesky.com/SoftChannel/72348981799157760/20031016/1736594.shtml"
target=_blank>深入了解安全技术</A><BR><A
href="http://www.yesky.com/SoftChannel/72348990389092352/20031015/1736179.shtml"
target=_blank>Dreamweaver MX 2004新功能试用</A><BR><A
href="http://www.yesky.com/SoftChannel/72342371928637440/20031014/1735874.shtml"
target=_blank>Visual Basic通用报表设计小结</A><BR><A
href="http://www.yesky.com/SoftChannel/72348986094125056/20030924/1731488.shtml"
target=_blank>设计教程节日大礼包</A><BR></TD></TR></TBODY></TABLE></TD>
<TD width=13 bgColor=#f7f7f7></TD>
<TD vAlign=top width=580 bgColor=#f7f7f7>
<TABLE height=1 cellSpacing=0 cellPadding=0 width=580
background=VC++程序员如何阅读ADO文档1.files/03-06.gif border=0>
<TBODY>
<TR>
<TD></TD></TR></TBODY></TABLE>
<P align=right><FONT color=red><A
href="http://www.yesky.com/SoftChannel/72342371928702976/20031021/1737617_4.shtml">上一页</A> <A
href="http://www.yesky.com/SoftChannel/72342371928702976/20031021/1737617.shtml">1</A>
<A
href="http://www.yesky.com/SoftChannel/72342371928702976/20031021/1737617_1.shtml">2</A>
<A
href="http://www.yesky.com/SoftChannel/72342371928702976/20031021/1737617_2.shtml">3</A>
<A
href="http://www.yesky.com/SoftChannel/72342371928702976/20031021/1737617_3.shtml">4</A>
<A
href="http://www.yesky.com/SoftChannel/72342371928702976/20031021/1737617_4.shtml">5</A>
6 <A
href="http://www.yesky.com/SoftChannel/72342371928702976/20031021/1737617_6.shtml">7</A>
<A
href="http://www.yesky.com/SoftChannel/72342371928702976/20031021/1737617_7.shtml">8</A>
<A
href="http://www.yesky.com/SoftChannel/72342371928702976/20031021/1737617_6.shtml">下一页</A></FONT></P><BR><SPAN
class=f14> <B>利用(IDispatch
*)转换ADO对象的指针类型</B><BR><BR> 1.在一个Variant中显式地封装一个活动的Connection对象,然后用(IDispatch
*)进行类型转换确保正确的构造函数被调用。同时明确地设置第二个参数为缺省的true,使该对象的引用计数在Recordset::Open操作完成后仍得到正确的维护。<BR><BR> 2.表达式(_bstr_t)不是一个类型转换,而是一个_variant_t的操作符,用以从中提取一个_bstr_t字符串。<BR><BR> 表达式(char*)也不是一个类型转换,而是一个_bstr_t的操作符,用以从中提取封装在_bstr_t中的字符串的指针。<BR><BR> 下面这些代码演示了_variant_t和_bstr_t的一些常见操作。<BR><BR>
<TABLE width="100%" bgColor=#ffffff>
<TBODY>
<TR>
<TD>#import "c:\Program Files\Common Files\System\ADO\msado15.dll"
\<BR>no_namespace rename("EOF", "EndOfFile")<BR><BR>#include
<stdio.h><BR><BR>void
main(void)<BR>{<BR>CoInitialize(NULL);<BR>try
<BR>{<BR>_ConnectionPtr pConn("ADODB.Connection");<BR>_RecordsetPtr
pRst("ADODB.Recordset");<BR><BR>pConn->Open("Provider=sqloledb;Data
Source=a-tima10;"<BR>"Initial Catalog=pubs;User Id=sa;Password=;",
<BR>"", "", adConnectUnspecified);<BR>// Note
1<BR>pRst->Open(<BR>"authors",<BR>_variant_t((IDispatch *) pConn,
true),<BR>adOpenStatic,<BR>adLockReadOnly,<BR>adCmdTable);<BR>pRst->MoveLast();<BR>//
Note 2<BR>printf("Last name is '%s %s'\n", <BR>(char*) ((_bstr_t)
pRst->GetFields()->GetItem("au_fname")->GetValue()),<BR>(char*)
((_bstr_t)
pRst->Fields->Item["au_lname"]->Value));<BR><BR>pRst->Close();<BR>pConn->Close();<BR>}<BR>catch
(_com_error &e)<BR>{<BR>printf("Description = '%s'\n", (char*)
e.Description());<BR>}
<BR>::CoUninitialize();<BR>}<BR></TD></TR></TBODY></TABLE><BR> 对于VC++程序员而言,每次都要将ADO返回的数据转换成一般的C++数据类型,接着将数据存入一个类或结构总是一件枯燥的事。更讨厌的是这也带来了效率的低下。<BR><BR> 因此,ADO提供了一个接口以支持将数据直接返回为一个本地化的C/C++数据类型而非VARIANT,并提供了一系列的预处理宏来方便使用这些接口。这样做的结果是一个复杂的工具可以很轻松的被使用并能获得很好的性能。<BR><BR> 一个普通的C/C++客户场景是将一个Recordset中的一条记录绑定到一个包含本地C/C++数据类型的C/C++结构或类之上。如果通过Variant传递数据,这意味着要编写大量的转换代码,以在VARIANT和C/C++本地类型间进行数据转换。VC++对ADO的扩展出现的目的就是要简化这一过程。<BR><BR></SPAN><BR>
<P align=right><FONT color=red><A
href="http://www.yesky.com/SoftChannel/72342371928702976/20031021/1737617_4.shtml">上一页</A> <A
href="http://www.yesky.com/SoftChannel/72342371928702976/20031021/1737617.shtml">1</A>
<A
href="http://www.yesky.com/SoftChannel/72342371928702976/20031021/1737617_1.shtml">2</A>
<A
href="http://www.yesky.com/SoftChannel/72342371928702976/20031021/1737617_2.shtml">3</A>
<A
href="http://www.yesky.com/SoftChannel/72342371928702976/20031021/1737617_3.shtml">4</A>
<A
href="http://www.yesky.com/SoftChannel/72342371928702976/20031021/1737617_4.shtml">5</A>
6 <A
href="http://www.yesky.com/SoftChannel/72342371928702976/20031021/1737617_6.shtml">7</A>
<A
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -