解决方案 »

  1.   

    粗看 应该是这个有问题:strQuery.Format(_T("select*from%s"), strTableName);改成这样试试,加上空格:strQuery.Format(_T("select * from %s"), strTableName);
      

  2.   


    试过了,还是不行,有什么调试方法能探究OPEN函数的错误信息呢?
      

  3.   

    这是我代码里的写法,可以正常使用m_pConnection->Open("Provider=SQLOLEDB.1;Password=123;Persist Security Info=True;User ID=sa;Initial Catalog=DFSF;Data Source=192.168.1.100,10000","","",adModeUnknown);
      

  4.   


    ::CoInitialize(NULL);
      
    try
    {
    // 创建Connection对象
    m_pConnection.CreateInstance(__uuidof(Connection));
    m_pConnection->Open("Provider=SQLOLEDB.1;Password=123;Persist Security Info=True;User ID=sa;Initial Catalog=DFSF;Data Source=192.168.1.100,10000","","",adModeUnknown);
    }
    // 捕捉异常
    catch(_com_error e)
    {
    // 显示错误信息
    AfxMessageBox(e.Description());
    }
    try
    {
    CString sqlstr="select * from model";
    // 创建记录集对象
    m_pRecordset.CreateInstance(__uuidof(Recordset));
    m_pRecordset->CursorLocation=adUseClient;
    // 取得表中的记录
    m_pRecordset->Open(_bstr_t(sqlstr),m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
    }
    catch(_com_error e)
    {
    // 显示错误信息
    AfxMessageBox(e.Description());
    }