怎样用ado打开dbf数据表?我用下面代码要报出非模式错误
   _ConnctionPtr m_con;
   _RecordsetPtr m_set;
   m_con.CreateInstance("ADODB.Connection");
   m_set.CreateInstance("ADODB.Recordset");
   m_con->Open("Driver={Microsoft dBase Driver(*.dbf)};DBQ=d:\\db\\;DriverID=277"},"","",adConnectUnspecofied);
   m_set->Open("select * from table1.dbf",_variant_t((IDispathc *)m_con,true),"","",adOpendynamic,adLockPessimistic,adCmdText);
  这是就要报出非模式错误了,debug出来是unhandle exception in:oxe06d7363
  换成以下语句一样的报错:
  m_set->Open("table1.dbf",_variant_t((IDispathc *)m_con,true),"","",adOpendynamic,adLockPessimistic,adCmdTable);那位老大给我讲解哈这是为什么,如何解决

解决方案 »

  1.   

    您好,
    我没有用ADO连过Microsoft dBase Driver,不太清楚它支持的Cursor类型和lock类型,建议您如果也不十分清楚Cursor类型与lock类型的支持的话,还是应该在程序功能允许的情况下选择尽可能保守的Cursor类型与lock类型。例如Cursor类型可以取adOpenForwardOnly, lock类型可以取adLockUnspecified。您有时间的话,这样试一下。祝您成功!
      

  2.   

    把类似 table1.dbf 这样的名字中“.dbf”全部去掉即可。
      

  3.   

    //=====================Open dbf database file
    #include "stdafx.h"
    #import "c:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF", "EndOfFile")
    int main(int argc, char* argv[])
    {
    printf("Use ADO to open c:\\tmp\\images.dbf database file!\n");
       CoInitialize(NULL);
       try
       {
          _ConnectionPtr pConn("ADODB.Connection");
          _RecordsetPtr  pRst("ADODB.Recordset");
    pConn->Open("Driver={Microsoft dBASE Driver (*.dbf)};DBQ=C:\\tmp\\; DriverID=533;"
    ,"","",adConnectUnspecified);
          pRst->Open("images", _variant_t((IDispatch *) pConn, true),
             adOpenStatic, adLockReadOnly, adCmdTable);
      FieldsPtr fds=pRst->GetFields();
      printf("printf field name of all the table\n");
      for(int i=0;i<fds->GetCount();i++)
      {
      FieldPtr fd=fds->GetItem(_variant_t(short(i)));
      printf("%s   ",(LPCTSTR)fd->GetName());
      }
      printf("\n");
          pRst->Close();
          pConn->Close();
       }
       catch (_com_error &e)
       {
          printf("Description = '%s'\n", (char*) e.Description());
       }
    ::CoUninitialize();
    return 0;
    }