我的email:[email protected]
          [email protected]
收到就给分。

解决方案 »

  1.   

    我记得要使用ado,一定要import "C:\..."
    这个包含的路径可不可以不要用绝对路径,因为系统盘有可能在c:有可能再d:
    能不能在程序自动找个这个路径啊!
      

  2.   

    路径问题可以通过GetCurrentDrectory()获得当前目录加以解决.
      

  3.   

    //#import 后面带的路径是编译器用的,相当于.h文件路径一样,你要在源程序中改,可执行文件没有这个路径要求
    #include "stdafx.h"
    #import "c:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF", "EndOfFile")int main(int argc, char* argv[])
    {
       CoInitialize(NULL);
       try
       {
          _ConnectionPtr pConn("ADODB.Connection");
          _RecordsetPtr  pRst("ADODB.Recordset");      pConn->Open("Provider=sqloledb;Data Source=Server1;"//Server1:机器名
             "Initial Catalog=test1;User Id=sa;Password=sa;",//test1:数据库名
             "", "", adConnectUnspecified);
    // Note 1.
          pRst->Open(
             "userinfo",//userinfo:table name
             _variant_t((IDispatch *) pConn, true),
             adOpenStatic,
             adLockReadOnly,
             adCmdTable);
          pRst->MoveLast();
    // Note 2.
          printf("Last name is '%s %s'\n",
                (char*) ((_bstr_t) pRst->GetFields()->GetItem("username")->GetValue()),
                (char*) ((_bstr_t) pRst->Fields->Item["otherinfo"]->Value));      pRst->Close();
          pConn->Close();
       }
       catch (_com_error &e)
       {
          printf("Description = '%s'\n", (char*) e.Description());
       }
    ::CoUninitialize();
    return 0;
    }
      

  4.   

    楼上的不错,不过既然已经用了no_namespace ,怎么还能出现ADO呢?
    没试过,我瞎说的。
      

  5.   

    各位,能不能给一段代码,怎样不用绝对路径!
    #import "C:\....." 怎样变啊?
      

  6.   

    你可以把msado15.dll拷贝到project目录下,然后用
    #import "msado15.dll" ...
      

  7.   

    在vc option 的目录中添上msado15.dll所在的路径。