#include "StdAfx.h" #include "StdArx.h" //----------------------------------------------------------------------------- // This is command 'LINK, by [2007-6-13], , void asdklink() { #ifdef OARXWIZDEBUG acutPrintf ("\nOARXWIZDEBUG - asdklink() called."); #endif // OARXWIZDEBUG // TODO: Implement the command ::CoInitialize(NULL); ADO::_ConnectionPtr connPtr; //AfxGetModuleState()->m_dwVersion = 0x0601; // HRESULT hr =connPtr.CreateInstance("ADODB.Connection"); HRESULT hr =connPtr.CreateInstance(__uuidof(Connection)); if(SUCCEEDED(hr)) { acutPrintf("Create Instance SUCCEEDED!"); return; } else { acutPrintf("Create Instance FAILED!"); } CString strConn; strConn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\PipeData.mdb"; _bstr_t varConn(strConn); if (FAILED(connPtr->Open(varConn,"","",-1))) { acutPrintf("Can not open Database!"); connPtr.Release(); return; } ADO::_RecordsetPtr recdPtr; if (FAILED(recdPtr.CreateInstance("ADODB.Recordset"))) { acutPrintf("recdPtr Create Instance failed!"); return; } CString strSql; strSql="select *from ([select 起始点号,终止点号,起点埋深,终点埋深 from dxl]. AS a INNER JOIN [select 物探点号 as 起点,X AS X1,Y AS Y1 from dxp]. AS b ON a.起始点号=b.起点) INNER JOIN [select 物探点号 as 终点,X AS X2,Y AS Y2 from dxp]. AS c ON a.终止点号=c.终点"; _variant_t varSql(strSql); //_variant_t varCon(strConn); if(FAILED(recdPtr->Open(varSql,connPtr.GetInterfacePtr(),ADO::adOpenDynamic,ADO::adLockOptimistic,ADO::adCmdText))) { acutPrintf("Open table failed!"); recdPtr.Release(); return; } else { acutPrintf("成功"); } } StdAfx.h已经引用了#import "C:\Program Files\Common Files\System\ado\msado15.dll" rename_namespace("ADO") rename("EOF","adoEOF") BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/) { AfxOleInit(); } |