title: How to query a Foxpro .DBF file with .NDX index file using the OLEDB driver in C#
body: <p>I have a Foxpro .DBF file. I am using OLEDB driver to read the .DBF file. I can query the DBF and utilize its .CDX index file(cause it is automatically opened). My problem is that I want to query it with the .NDX index file (which is not automatically opened when the .DBF is opened). How can I open the .NDX file in C# using OLEDB driver cause the DBF is really big to search for a record without the index? Thanks all! Here is the code I am using to read the DBF.</p>
  
  <pre><code>OleDbConnection oleDbConnection = null;
          try
          {
              DataTable resultTable = new DataTable();
              using (oleDbConnection = new OleDbConnection("Provider=VFPOLEDB.1;Data Source=P:\\Test\\DSPC-1.DBF;Exclusive=No"))
              {
                  oleDbConnection.Open();
                  if (oleDbConnection.State == ConnectionState.Open)
                  {
                      OleDbDataAdapter dataApdapter = new OleDbDataAdapter();
                      OleDbCommand command = oleDbConnection.CreateCommand();
  
                      string selectCmd = @"select * from P:\Test\DSPC-1  where dp_file = '860003'";
                      command.CommandType = CommandType.Text;
                      command.CommandText = selectCmd;
  
                      dataApdapter.SelectCommand = command;
                      dataApdapter.Fill(resultTable);
                      foreach(DataRow row in resultTable.Rows)
                      {
                          //Write the data of each record 
                      }
                  }
              }
          }
          catch (Exception e)
          {
              Console.WriteLine(e.Message);
          }
          finally
          {
              try
              {
                  oleDbConnection.Close();
              }
              catch (Exception e)
              {
                  Console.WriteLine("Failed to close Oledb connection: " + e.Message);
              }
          }
  </code></pre>