¡¡¡¡VCÔÚ¿ØÖÆÌ¨Ä£Ê½Ï·ÃÎÊOracleÊý¾Ý¿âµÄ²Ù×÷Ö¸Á´úÂëÈçÏ£º
¡¡¡¡#include <afx.h>
¡¡¡¡#include <iostream>
¡¡¡¡#import "C:\Program Files\Common Files\System\ADO\msado15.dll" no_namespace rename£¨"EOF","adoEOF"£©
¡¡¡¡using namespace std;
¡¡¡¡#define BUFSIZE 64
¡¡¡¡int main£¨£©
¡¡¡¡{
¡¡¡¡//char buf[BUFSIZE];
¡¡¡¡//int index;
¡¡¡¡_ConnectionPtr m_pConnection;
¡¡¡¡CoInitialize£¨NULL£©£»//³õʼ»¯COM×é¼þ
¡¡¡¡HRESULT hr=m_pConnection.CreateInstance£¨__uuidof£¨Connection£©£©£»
¡¡¡¡if£¨SUCCEEDED£¨hr£©£©
¡¡¡¡{
¡¡¡¡cout¡¶"´´½¨Connection¶ÔÏó³É¹¦£¡"¡¶endl;
¡¡¡¡}
¡¡¡¡try
¡¡¡¡{
¡¡¡¡_bstr_t strConnect="Provider=OraOLEDB.Oracle;User ID=scott;Password=19900624;Persist Security Info=True;Data Source=\"£¨DESCRIPTION =£¨ADDRESS_LIST =£¨ADDRESS = £¨PROTOCOL = TCP£©£¨HOST = 10.108.85.137£©£¨PORT = 1521£©£© £©£¨CONNECT_DATA = £¨SID = ORCL£©£¨SERVER=DEDICATED£©£©£©\"";
¡¡¡¡hr=m_pConnection->Open£¨strConnect,"","",NULL£©£»
¡¡¡¡if£¨SUCCEEDED£¨hr£©£©
¡¡¡¡cout¡¶"Êý¾Ý¿âÒÑÁ¬½Ó£¡"¡¶endl;
¡¡¡¡}
¡¡¡¡catch£¨_com_error e£© //²¶×½Òì³£
¡¡¡¡{
¡¡¡¡cout¡¶e.ErrorMessage£¨£©¡¶e.Description£¨£©¡¶endl;
¡¡¡¡//cout¡¶"error"¡¶endl;
¡¡¡¡return FALSE;
¡¡¡¡}
¡¡¡¡/////////////////²éѯÊý¾Ý¿â²Ù×÷//////////////////////
¡¡¡¡_variant_t var1;
¡¡¡¡_RecordsetPtr m_pRecordset=NULL; //´´½¨Ò»¸öÊý¾Ý¼¯ÖÇÄÜÖ¸Õë
¡¡¡¡m_pRecordset.CreateInstance£¨__uuidof£¨Recordset£©£©£»//³õʼ»¯RecordsetÖ¸Õë
¡¡¡¡char *content;
¡¡¡¡char type;
¡¡¡¡cin¡·type;
¡¡¡¡switch£¨type£©
¡¡¡¡{
¡¡¡¡case 's':
¡¡¡¡try
¡¡¡¡{
¡¡¡¡CString sql;
¡¡¡¡sql="select * from DB_USER";
¡¡¡¡m_pRecordset=m_pConnection->Execute£¨£¨_bstr_t£©sql,NULL,adCmdText£©£»
¡¡¡¡}
¡¡¡¡catch£¨_com_error *e£©
¡¡¡¡{
¡¡¡¡cout¡¶e->ErrorMessage£¨£©¡¶endl;
¡¡¡¡}
¡¡¡¡try
¡¡¡¡{
¡¡¡¡if£¨£¡m_pRecordset->BOF£©
¡¡¡¡{
¡¡¡¡m_pRecordset->MoveFirst£¨£©£»
¡¡¡¡}
¡¡¡¡else
¡¡¡¡{
¡¡¡¡cout¡¶"±íÄÚΪ¿Õ"¡¶endl;
¡¡¡¡}
¡¡¡¡while£¨£¡m_pRecordset->adoEOF£©
¡¡¡¡{
¡¡¡¡//var1=m_pRecordset->Fields->GetItem£¨"USERNAME"£©->GetValue£¨£©£»
¡¡¡¡var1=m_pRecordset->GetCollect£¨"USERNAME"£©£»
¡¡¡¡m_pRecordset->MoveNext£¨£©£»
¡¡¡¡if£¨var1.vt!=VT_NULL£©
¡¡¡¡{
¡¡¡¡content=_com_util::ConvertBSTRToString£¨£¨_bstr_t£©var1£©£»
¡¡¡¡}
¡¡¡¡cout¡¶"´ÓÊý¾Ý¿âµÃµ½Êý¾Ý£º"¡¶content¡¶endl;
¡¡¡¡}
¡¡¡¡}
¡¡¡¡catch£¨_com_error *e£©
¡¡¡¡{
¡¡¡¡cout¡¶e->ErrorMessage£¨£©¡¶endl;
¡¡¡¡}
¡¡¡¡break;
¡¡¡¡case 'd':