0

我有一个 DBF 文件和一个索引文件。我想读取索引文件和搜索记录满足一些条件。(例如:使用Student.DBF和StudentName.idx搜索StudentName以“A”开头的记录)

如何以编程方式执行此操作?

4

2 回答 2

0

我没有想到代码,但是如果您不想使用 ODBC,那么您应该考虑阅读 ESRI 形状文件,它们由 3 部分(或更多)一个 .DBF(您正在寻找的)、一个 PRJ 文件和一个 .SHP 文件。这可能需要一些工作,但您应该能够挖掘出代码。你应该看看codeplex 上的Sharpmap。读取没有 ODBC 的 dbf 并不是一项简单的任务,但它可以完成,并且有很多代码可以做到这一点。您必须处理大端与小端值,以及一系列文件版本。

如果你去这里, 你会发现读取 dbf 文件的代码。具体来说,您会对该public void ReadAttributes( Stream stream )方法感兴趣。

于 2010-02-02T14:20:14.860 回答
0

最容易通过 OleDB Connection 查询

using System.Data.OleDb;
using System.Data;


OleDbConnection oConn = new OleDbConnection("Provider=VFPOLEDB.1;Data Source=C:\\PathToYourDataDirectory"); 
OleDbCommand oCmd = new OleDbCommand(); 
oCmd.Connection = oConn; 
oCmd.Connection.Open(); 
oCmd.CommandText = "select * from SomeTable where LEFT(StudentName,1) = 'A'"; 

// Create an OleDBAdapter to pull data down
// based on the pre-built SQL command and parameters
OleDbDataAdapter oDA = new OleDbDataAdapter(oCmd);
DataTable YourResults
oDA.Fill(YourResults);
oConn.Close(); 


// then you can scan through the records to get whatever
String EachField = "";
foreach( DataRow oRec in YourResults.Rows )
{
  EachField = oRec["StudentName"];
  // but now, you have ALL fields in the table record available for you

}
于 2010-02-02T14:13:52.307 回答