使用 .idx 文件在 DBF 文件中搜索

发布于 2024-08-20 03:51:34 字数 133 浏览 8 评论 0原文

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

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

I have a DBF file and a index file.
I want to read index file and search records satisfy some condition.
(for example: search records which its StudentName begin with "A" by using Student.DBF and StudentName.idx)

How do I do this programmatically?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寒尘 2024-08-27 03:51:34

通过 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

}

It would be easiest to query via 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

}
最偏执的依靠 2024-08-27 03:51:34

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

如果您访问此处,您将找到读取 dbf 文件的代码。具体来说,您可能会对 public void ReadAttributes( Stream stream ) 方法感兴趣。

I dont have the code off the top of my head, but if you do not want to use ODBC, then you should look into reading ESRI shape files, they consist of 3 parts (or more) a .DBF (what you are looking for), a PRJ file and a .SHP file. It could take some work, but you should be able to dig out the code. You should take a look at Sharpmap on codeplex. It's not a simple task to read a dbf w/o ODBC but it can be done, and there is a lot of code out there for doing this. You have to deal with big-endian vs little-endian values, and a range of file versions as well.

if you go here you will find code to read a dbf file. specifically, you would be interested in the public void ReadAttributes( Stream stream ) method.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文