Search in DBF file using .idx file
Asked Answered
B

2

0

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?

Bayern answered 2/2, 2010 at 13:57 Comment(2)
Do you mean, "How do I do this programmatically?" or "How do I do this via ODBC?"Zabaglione
so, programmatically using ODBC? or not?Refrigeration
C
0

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

}
Christchurch answered 2/2, 2010 at 14:13 Comment(0)
O
0

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.

Obvious answered 2/2, 2010 at 14:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.