//=====================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;
}

解决方案 »

  1.   

    我的意思是直接操作dbf文件,不用ADO,ODBC等
      

  2.   

    i am enclosing a more accurate file layout. note it include 
    dbaseiii+, dbaseiv, foxbase, foxpro upto and including 2.6.
    dbf file structure
    ~~~~~~~~~~~~~~~~~~bytes description
    00    foxbase+, foxpro, dbaseiii+, dbaseiv, no memo - 0x03
    foxbase+, dbaseiii+ with memo - 0x83
        foxpro with memo - 0xf5
        dbaseiv with memo - 0x8b
        dbaseiv with sql table - 0x8e01-03 last update, format yyyymmdd **correction: it is yymmdd**
    04-07    number of records in file (32-bit number)
    08-09    number of bytes in header (16-bit number)
    10-11    number of bytes in record (16-bit number)
    12-13    reserved, fill with 0x00
    14    dbaseiv flag, incomplete transaction
    begin transaction sets it to 0x01
        end transaction or rollback reset it to 0x0015 encryption flag, encrypted 0x01 else 0x00
    changing the flag does not encrypt or decrypt the records16-27 dbaseiv multi-user environment use
    28    production index exists - 0x01 else 0x00
    29    dbaseiv language driver id
    30-31 reserved fill with 0x00
    32-n    field descriptor array
    n+1    header record terminator - 0x0dfield descriptor array table
    bytes description
    0-10 field name ascii padded with 0x00
    11    field type identifier (see table)
    12-15    displacement of field in record
    16    field length in bytes
    17    field decimal places
    18-19    reserved
    20    dbaseiv work area id
    21-30    reserved
    31     field is part of production index - 0x01 else 0x00field identifier table
    ascii description
    c character
    d date, format yyyymmdd
    f floating point
    g general - foxpro addition
    l logical, t:t,f:f,y:y,n:n,?-not initialized
    m memo (stored as 10 digits representing the dbt block number)
    n numeric
    p picture - foxpro additionnote all dbf field records begin with a deleted flag field.
    if record is deleted - 0x2a (asterisk) else 0x20 (space)
    end of file is ed with 0x1a
      

  3.   

    如何直接读写dbf文件,请高手赐教!!!
      

  4.   

    谁有操作dbf文件类?再加100分!!!
      

  5.   

    我有,想要的话发邮件到我的mail
    [email protected]