{"id":419,"date":"2010-05-10T15:52:00","date_gmt":"2010-05-10T07:52:00","guid":{"rendered":"http:\/\/www.prayerlaputa.com\/?p=419"},"modified":"2019-10-24T19:24:40","modified_gmt":"2019-10-24T11:24:40","slug":"_recordsetptr%e7%9a%84-open%e5%87%bd%e6%95%b0%e8%bd%ac%e8%bd%bd","status":"publish","type":"post","link":"http:\/\/prayerlaputa.com\/?p=419","title":{"rendered":"_RecordsetPtr\u7684 open\u51fd\u6570(\u8f6c\u8f7d)"},"content":{"rendered":"<div id=\"blog_text\">\u8f6c\u81ea\uff1ahttp:\/\/hi.baidu.com\/ruiqing_2008\/blog\/item\/50381334c10183bbd1a2d369.html<br \/>\n_RecordsetPtr m_pRecordset;\/\/\u521b\u5efa\u4e00\u4e2a_RecordsetPtr m_pRecordset.CreateInstance(&#8220;ADODB.Recordset&#8221;); \/\/\u521b\u5efa\u4e00\u4e2a\u5b9e\u4f8b try {\u00a0\u00a0 \u00a0\u00a0 m_pRecordset-&gt;Open(<br \/>\n&#8220;SELECT * FROM duty&#8221;,\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/sql\u67e5\u8be2\u8bed\u53e5<br \/>\nm_pConnection.GetInterfacePtr(),\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/\u5f97\u5230sql\u8fde\u63a5\u7684\u6307\u9488<br \/>\n\/\/Const <strong style=\"color: black; background-color: #ffff66;\">adOpenDynamic<\/strong> = 2 &#8216;\u52a8\u6001\u6e38\u6807\u529f\u80fd\u6700\u5f3a\uff0c\u4f46\u8017\u8d44\u6e90\u4e5f\u6700\u591a\u3002\u7528\u6237\u5bf9\u8bb0\u5f55\u8bf4\u505a\u7684\u4fee\u6539\uff0c\u589e\u52a0\u6216\u5220\u9664\u8bb0\u5f55\u90fd\u5c06\u53cd\u6620\u5230\u8bb0\u5f55\u96c6\u4e2d\u3002\u652f\u6301\u5168\u529f\u80fd\u6d4f\u89c8(ACCESS\u4e0d\u652f\u6301)\u3002<br \/>\nadOpenDynamic,<br \/>\n<!--more--><br \/>\n\/\/Const adLockOptimistic = 3 &#8216;\u53ea\u6709\u5728\u8c03\u7528Update\u65b9\u6cd5\u65f6\u624d\u9501\u5b9a\u8bb0\u5f55\u96c6\uff0c\u800c\u5728\u6b64\u524d\u7684\u5176\u4ed6\u64cd\u4f5c\u4ecd\u53ef\u5bf9\u5f53\u524d\u8bb0\u5f55\u8fdb\u884c\u66f4\u6539\u3001\u63d2\u5165\u548c\u5220\u9664 \u7b49<br \/>\nadLockOptimistic,<br \/>\n\/\/<strong>AdCmdText<\/strong> \u5c06 CommandText \u4f5c\u4e3a\u547d\u4ee4\u6216\u5b58\u50a8\u8fc7\u7a0b\u8c03\u7528\u7684\u6587\u672c\u5316\u5b9a\u4e49\u8fdb\u884c\u8ba1\u7b97\u3002<br \/>\nadCmdText);<br \/>\n}<br \/>\ncatch(_com_error e)<br \/>\n{<br \/>\n\/\/cout&lt;&lt;e-&gt;ErrorMessage()&lt;&lt;endl;<br \/>\nAfxMessageBox(&#8220;Create Instance failed!&#8221;);<br \/>\nreturn;<br \/>\n}<\/p>\n<p><strong>\u5185\u5bb9\u4e00\uff1a<\/strong><br \/>\n&#8216;\u5b9a\u4e49\u6570\u636e\u5e93\u8fde\u63a5\u7684\u4e00\u4e9b\u5e38\u91cf<br \/>\nConst adOpenForwardOnly = 0 &#8216;(\u9ed8\u8ba4\u503c)\u6e38\u6807\u53ea\u5411\u524d\u6d4f\u89c8\u8bb0\u5f55\uff0c\u4e0d\u652f\u6301\u5206\u9875\u3001Recordset\u3001BookMark<br \/>\nConst adOpenKeyset = 1 &#8216;\u952e\u96c6\u6e38\u6807\uff0c\u5176\u4ed6\u7528\u6237\u5bf9\u8bb0\u5f55\u8bf4\u505a\u7684\u4fee\u6539\u5c06\u53cd\u6620\u5230\u8bb0\u5f55\u96c6\u4e2d\uff0c\u4f46\u5176\u4ed6\u7528\u6237\u589e\u52a0\u6216\u5220\u9664\u8bb0\u5f55\u4e0d\u4f1a\u53cd\u6620\u5230\u8bb0\u5f55\u96c6\u4e2d\u3002\u652f\u6301\u5206\u9875\u3001Recordset\u3001BookMark<br \/>\nConst <strong style=\"color: black; background-color: #ffff66;\">adOpenDynamic<\/strong> = 2 &#8216;\u52a8\u6001\u6e38\u6807\u529f\u80fd\u6700\u5f3a\uff0c\u4f46\u8017\u8d44\u6e90\u4e5f\u6700\u591a\u3002\u7528\u6237\u5bf9\u8bb0\u5f55\u8bf4\u505a\u7684\u4fee\u6539\uff0c\u589e\u52a0\u6216\u5220\u9664\u8bb0\u5f55\u90fd\u5c06\u53cd\u6620\u5230\u8bb0\u5f55\u96c6\u4e2d\u3002\u652f\u6301\u5168\u529f\u80fd\u6d4f\u89c8(ACCESS\u4e0d\u652f\u6301)\u3002<br \/>\nConst adOpenStatic = 3 &#8216;\u9759\u6001\u6e38\u6807\uff0c\u53ea\u662f\u6570\u636e\u7684\u4e00\u4e2a\u5feb\u7167\uff0c\u7528\u6237\u5bf9\u8bb0\u5f55\u8bf4\u505a\u7684\u4fee\u6539\uff0c\u589e\u52a0\u6216\u5220\u9664\u8bb0\u5f55\u90fd\u4e0d\u4f1a\u53cd\u6620\u5230\u8bb0\u5f55\u96c6\u4e2d\u3002\u652f\u6301\u5411\u524d\u6216\u5411\u540e\u79fb\u52a8<br \/>\nConst adLockReadOnly = 1 &#8216;(\u9ed8\u8ba4\u503c)\u9501\u5b9a\u7c7b\u578b\uff0c\u9ed8\u8ba4\u7684\uff0c\u53ea\u8bfb\uff0c\u4e0d\u80fd\u4f5c\u4efb\u4f55\u4fee\u6539<br \/>\nConst adLockPessimistic = 2 &#8216;\u5f53\u7f16\u8f91\u65f6\u7acb\u5373\u9501\u5b9a\u8bb0\u5f55\uff0c\u6700\u5b89\u5168\u7684\u65b9\u5f0f<br \/>\nConst adLockOptimistic = 3 &#8216;\u53ea\u6709\u5728\u8c03\u7528Update\u65b9\u6cd5\u65f6\u624d\u9501\u5b9a\u8bb0\u5f55\u96c6\uff0c\u800c\u5728\u6b64\u524d\u7684\u5176\u4ed6\u64cd\u4f5c\u4ecd\u53ef\u5bf9\u5f53\u524d\u8bb0\u5f55\u8fdb\u884c\u66f4\u6539\u3001\u63d2\u5165\u548c\u5220\u9664\u7b49<br \/>\nConst adLockBatchOptimistic = 4 &#8216;\u5f53\u7f16\u8f91\u65f6\u8bb0\u5f55\u4e0d\u4f1a\u88ab\u9501\u5b9a\uff0c\u800c\u66f4\u6539\u3001\u63d2\u5165\u548c\u5220\u9664\u662f\u5728\u6279\u5904\u7406\u65b9\u5f0f\u4e0b\u5b8c\u6210\u7684<br \/>\nConst adCmdText = &amp;H0001<br \/>\nConst adCmdTable = &amp;H0002<br \/>\n%&gt;<br \/>\nOpen \u65b9\u6cd5 (ADO Recordset)<br \/>\n\u6253\u5f00\u6e38\u6807\u3002<br \/>\n\u8bed\u6cd5<br \/>\nrecordset.Open Source, ActiveConnection, CursorType, LockType, Options<br \/>\n<strong>\u5185\u5bb9\u4e8c\uff1a<\/strong><br \/>\nCommandType \u5c5e\u6027<br \/>\n\u6307\u793a Command \u5bf9\u8c61\u7684\u7c7b\u578b\u3002<br \/>\n\u8bbe\u7f6e\u548c\u8fd4\u56de\u503c<br \/>\n\u8bbe\u7f6e\u6216\u8fd4\u56de\u4ee5\u4e0b\u67d0\u4e2a CommandTypeEnum \u503c\u3002<br \/>\n\u5e38\u91cf \u8bf4\u660e<br \/>\n<strong style=\"color: black; background-color: #ffff66;\">AdCmdText<\/strong> \u5c06 CommandText \u4f5c\u4e3a\u547d\u4ee4\u6216\u5b58\u50a8\u8fc7\u7a0b\u8c03\u7528\u7684\u6587\u672c\u5316\u5b9a\u4e49\u8fdb\u884c\u8ba1\u7b97\u3002<br \/>\nAdCmdTable \u5c06 CommandText \u4f5c\u4e3a\u5176\u5217\u5168\u90e8\u7531\u5185\u90e8\u751f\u6210\u7684 SQL \u67e5\u8be2\u8fd4\u56de\u7684\u8868\u683c\u7684\u540d\u79f0\u8fdb\u884c\u8ba1\u7b97\u3002<br \/>\nAdCmdTableDirect \u5c06 CommandText \u4f5c\u4e3a\u5176\u5217\u5168\u90e8\u8fd4\u56de\u7684\u8868\u683c\u7684\u540d\u79f0\u8fdb\u884c\u8ba1\u7b97\u3002<br \/>\nAdCmdStoredProc \u5c06 CommandText \u4f5c\u4e3a\u5b58\u50a8\u8fc7\u7a0b\u540d\u8fdb\u884c\u8ba1\u7b97\u3002<br \/>\nAdCmdUnknown \u9ed8\u8ba4\u503c\u3002CommandText \u5c5e\u6027\u4e2d\u7684\u547d\u4ee4\u7c7b\u578b\u672a\u77e5\u3002<br \/>\nadCmdFile \u5c06 CommandText \u4f5c\u4e3a\u6301\u4e45 Recordset \u6587\u4ef6\u540d\u8fdb\u884c\u8ba1\u7b97\u3002<br \/>\nAdExecuteNoRecords \u6307\u793a CommandText \u4e3a\u4e0d\u8fd4\u56de\u884c\u7684\u547d\u4ee4\u6216\u5b58\u50a8\u8fc7\u7a0b\uff08\u4f8b\u5982\uff0c\u63d2\u5165\u6570\u636e\u7684\u547d\u4ee4\uff09\u3002\u5982\u679c\u68c0\u7d22\u4efb\u610f\u884c\uff0c\u5219\u5c06\u4e22\u5f03\u8fd9\u4e9b\u884c\u4e14\u5e76\u4e0d\u8fd4\u56de\u3002\u5b83\u603b\u662f\u4e0e <strong style=\"color: black; background-color: #ffff66;\">adCmdText<\/strong> \u6216 adCmdStoredProc \u8fdb\u884c\u7ec4\u5408\u3002<br \/>\n\u8bf4\u660e<br \/>\n\u4f7f\u7528 CommandType \u5c5e\u6027\u53ef\u4f18\u5316 CommandText \u5c5e\u6027\u7684\u8ba1\u7b97\u3002<br \/>\n\u5982\u679c CommandType \u5c5e\u6027\u7684\u503c\u7b49\u4e8e adCmdUnknown\uff08\u9ed8\u8ba4\u503c\uff09\uff0c\u7cfb\u7edf\u7684\u6027\u80fd\u5c06\u4f1a\u964d\u4f4e\uff0c\u56e0\u4e3a ADO \u5fc5\u987b\u8c03\u7528\u63d0\u4f9b\u8005\u4ee5\u786e\u5b9a CommandText \u5c5e\u6027\u662f SQL \u8bed\u53e5\u3001\u8fd8\u662f\u5b58\u50a8\u8fc7\u7a0b\u6216\u8868\u683c\u540d\u79f0\u3002\u5982\u679c\u77e5\u9053\u6b63\u5728\u4f7f\u7528\u7684\u547d\u4ee4\u7684\u7c7b\u578b\uff0c\u53ef\u901a\u8fc7\u8bbe\u7f6e CommandType \u5c5e\u6027\u6307\u4ee4 ADO \u76f4\u63a5\u8f6c\u5230\u76f8\u5173\u4ee3\u7801\u3002\u5982\u679c CommandType \u5c5e\u6027\u4e0e CommandText \u5c5e\u6027\u4e2d\u7684\u547d\u4ee4\u7c7b\u578b\u4e0d\u5339\u914d\uff0c\u8c03\u7528 Execute \u65b9\u6cd5\u65f6\u5c06\u4ea7\u751f\u9519\u8bef\u3002<br \/>\nadExecuteNoRecords \u5e38\u91cf\u901a\u8fc7\u6700\u5c0f\u5316\u5185\u90e8\u5904\u7406\u6765\u63d0\u9ad8\u6027\u80fd\u3002\u8be5\u5e38\u91cf\u4e0d\u72ec\u7acb\u4f7f\u7528\uff0c\u5b83\u603b\u662f\u4e0e <strong style=\"color: black; background-color: #ffff66;\">adCmdText<\/strong> \u6216 adCmdStoredProc \u7ec4\u5408\uff08\u5982 <strong style=\"color: black; background-color: #ffff66;\">adCmdText<\/strong>+adExecuteNoRecords\uff09 \u4e00\u8d77\u4f7f\u7528\u3002\u5982\u679c\u4e0e Recordset.Open \u4e00\u8d77\u4f7f\u7528 adExecuteNoRecords\uff0c\u6216\u8005\u8be5\u65b9\u6cd5\u4f7f\u7528 Command \u5bf9\u8c61\u90fd\u5c06\u4ea7\u751f\u9519\u8bef\u3002<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u8f6c\u81ea\uff1ahttp:\/\/hi.baidu.com\/ruiqing_2008\/blog\/item\/50381334c <a href='http:\/\/prayerlaputa.com\/?p=419' class='excerpt-more'>[&#8230;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[4],"tags":[28],"_links":{"self":[{"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=\/wp\/v2\/posts\/419"}],"collection":[{"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=419"}],"version-history":[{"count":1,"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=\/wp\/v2\/posts\/419\/revisions"}],"predecessor-version":[{"id":692,"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=\/wp\/v2\/posts\/419\/revisions\/692"}],"wp:attachment":[{"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=419"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=419"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=419"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}