要求不用odbc连接的。谢谢。给我一个查询数据库表的例子就行

解决方案 »

  1.   

    http://www.sron.net/infoview/Article_483.html
      

  2.   

    那就用ADO连接吧
    访问ORACLE数据库 
    "Provider=MSDAORA;Data Source=serverName;User ID=userName; Password=userPassword;" 
    访问MS SQL数据库 
    "Provider=SQLOLEDB;Data Source=serverName;Initial Catalog=databaseName; User ID=userName;Password=userPassword;" 
    访问ACCESS 数据库 
    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=databaseName;User ID=userName;Password=userPassword;" 看看下面的文章:
    http://www.vckbase.com/document/viewdoc/?id=215
    http://www.vckbase.com/document/viewdoc/?id=249
      

  3.   

    为什么到了if(FAILED(hr)) return;
    就执行不过去了,
    HRESULT hr=pMyConnect.CreateInstance(__uuidof( Connection ) );
    这句话有错误吗?_ConnectionPtr pMyConnect=NULL;
    HRESULT hr=pMyConnect.CreateInstance(__uuidof( Connection ) );
    if(FAILED(hr)) return;
    _bstr_t strConnect="Provider=SQLOLEDB; Server=gooyan;Database=dataname; uid=sa; pwd=aaa;"; 
    //connecting to the database server now:
    try{pMyConnect->Open(strConnect,"","",NULL);}
    catch (_com_error &e)
    {
    ::MessageBox(NULL,e.Description(),"警告",MB_OK | MB_ICONWARNING);
    }
      

  4.   

    1.ACCESS 2000    _ConnectionPtr m_pConn;
        CString m_sConn="Provider=Microsoft.Jet.OLEDB.4.0.1;Data Source=d:\\db1.mdb";
        m_pConn.CreateInstance("ADODB.Connection");
        try
        {
            HRESULT hr=m_pConn->Open((_bstr_t)m_sConn,"","",adConnectUnspecified);    
            if (FAILED(hr))
            {
                AfxMessageBox("不能连接数据库 source!");
                return FALSE;
            }
        }
        catch(_com_error e)
        {
            AfxMessageBox("不能连接数据库 error!");
            return FALSE;
        }2.SQL Server 2000    _ConnectionPtr m_pConn;
        CString m_sConn="Provider=SQLOLEDB.1;Data Source=192.168.3.9;Initial 
    Catalog=sode"; //sode是数据库服务器192.168.3.9上的一个数据库
        m_pConn.CreateInstance("ADODB.Connection");
        try
        {
            HRESULT hr=m_pConn->Open((_bstr_t)m_sConn,"sa","mapper",adConnectUnspecified);    
            if (FAILED(hr))
            {
                AfxMessageBox("不能连接数据库 source!");
                return FALSE;
            }
        }
        catch(_com_error e)
        {
            AfxMessageBox("不能连接数据库 error!");
            return FALSE;
        }3.Oracle 9i    _ConnectionPtr m_pConn;
        CString m_sConn="Provider=MSDAORA.1;Data Source=sode_192.168.3.9"; //使用
    ms连接库,sode为SID,192.168.3.9为机器ip
        m_pConn.CreateInstance("ADODB.Connection");
        try
        {
            HRESULT hr=m_pConn->Open((_bstr_t)m_sConn,"sodeUser","sodePw",adConnectUnspecified);    
            if (FAILED(hr))
            {
                AfxMessageBox("不能连接数据库 source!");
                return FALSE;
            }
        }
        catch(_com_error e)
        {
            AfxMessageBox("不能打开数据库 error!");
            return FALSE;
        }
    ===>Oracle Connect String微软提供的Oracle标准连接是:strConnect = _T("Provider=MSDAORA;Data Source=serverName;User ID=userName; Password=userPassword;");Oracle公司提供的连接方式:使用标准安全级别:strConnect = _T("Provider=OraOLEDB.Oracle;Data Source=MyOracleDB;User Id=myUsername;Password=myPassword;");使用信任连接1.strConnect = _T("Provider=OraOLEDB.Oracle;Data Source=MyOracleDB;User Id=/;Password=;"); UID为'/'2.strConnect = _T("Provider=OraOLEDB.Oracle;Data Source=MyOracleDB;OSAuthent=1;");使用OSAuthent=1对于连接字符串可以参考以下网页: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdreforacleprovspec.asp?frame=truehttp://download-west.oracle.com/otndoc/oracle9i/901_doc/win.901/a90171/using.htm