.NET读取foxpro dbf文件

首先,从微软网站下载odbc_net.msi,VFPODBC.msi,并且安装。代码如下:

DataSet ds = new DataSet();

string dbf_connstring = "Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB=d:/dbfata;Exclusive=No;Collate=Machine;NULL=NO;DELETED=NO;BACKGROUNDFETCH=NO";//其中d:/dbfdata为你的foxpro dbf文件夹。

OdbcDataAdapter odbcAdapter = new OdbcDataAdapter();
   Console.WriteLine("DBF Connection ready...");
   OdbcConnection dbf_conn = new OdbcConnection(dbf_connstring);
   try
   {
    dbf_conn.Open();
    Console.WriteLine("DBF Connection ok...");
   }
   catch(Exception e1)
   {
    Console.WriteLine("DBF Connection fail...");
    Console.WriteLine(e1.Message);
   }
   Console.WriteLine("Query Info...");
   dbf_sql = "select wip_no as wo_no,wip_line as wo_seq,item_no as model,create_dat as create_date,plan_qty as wo_qty,make_qty as complete_qty,wip_type as wo_type from wip_header";
   odbcAdapter = new OdbcDataAdapter(dbf_sql,dbf_conn);
   try
   {
    odbcAdapter.Fill(ds);
   }
   catch(Exception e2)
   {
    Console.WriteLine(e2.Message);
   }

你可能感兴趣的:(.NET读取foxpro dbf文件)