我想编一个Delphi程序,在程序运行时出现一个数据连接向导(就像Delphi中的ADO数据库连接向导那样),请问应该怎么做?

解决方案 »

  1.   

    #define _ADO_VER 0x0207
    #if _ADO_VER >= 0x0201
    // NOTE: UNCOMMENT FOLLOWING LINE IF USING MDAC 2.1 (ADO 2.1) and comment line with Msdasc.dll. 
    #import "C:\Program Files\Common Files\System\OLE DB\OLEDB32.dll" rename_namespace("dl20")
    #else
    // NOTE: UNCOMMENT FOLLOWING LINE IF USING MDAC 2.0 (ADO 2.0) and comment above line. 
    #import "G:\Program Files\Common Files\System\OLE DB\Msdasc.dll" rename_namespace("dl20")
    #endif
    //Reason: Datalink connection string builder, was moved to oledb32.dll in ADO2.1 
    //where as in ADO2.0 it was located in Msdasc.dll (ADO2.0)#import "G:\Program Files\Common Files\SYSTEM\ADO\MSADO15.DLL" rename_namespace("ado20")
    using namespace ado20;
    void CAdoDataGridView::OnBuildconnstr() 
    {
    using namespace dl20; // DataLinks #import
    using namespace ado20; // ADO #import
    HRESULT hr;
    IDataSourceLocatorPtr dlPrompt = NULL;
    _ConnectionPtr conn = NULL;

    ::CoInitialize( NULL ); //Launch DataLink connection dialog
    hr = dlPrompt.CreateInstance(__uuidof(DataLinks));
    conn = dlPrompt->PromptNew();
    if ( conn!=NULL )
    {
    m_strConnect.Format( "%s", (char*) conn->ConnectionString );
    UpdateData( FALSE );
    }
    }