oledb, visual fox pro y c#

I have visual fox pro database with thousands of rows. I am using oledb to fetch data from fox pro and export(after doing some calculation and fomatting) it to sql server.I have used dataset to populate 2-3 datatable(related table) at a time.

First problem is that the memory use is very high because the dataset are huge.I want to reduce memory footprint.Any suggestion for this.

So i have decided to fetch few rows at a time.How do i fetch rows using oledb command so that i can fetch for eg 1-20 and then 20-40 etc

preguntado el 31 de julio de 12 a las 10:07

2 Respuestas

Based on all the comments and HatSoft's code here is what I think you are looking for. This is pseudo-code, whcih means it will not compile but should give you a good idea of where to go from here.

int NumberOfRecordsToRetrieve = 10000;
int StartRecordNumber = 1;
bool EndOfFile = false;

 string queryString = "SELECT OrderID, CustomerID FROM Orders WHERE RECNO() BETWEEN @StartRecordNumber AND @EndRecordNumber"; 

While (!EndOfFile)
{
     using (OleDbConnection connection = new OleDbConnection(connectionString)) 
     { 
         OleDbCommand command = new OleDbCommand(queryString, connection); 
         command.Parameters.Add(new OleDbParameter("@StartRecordNumber", StartRecordNumber)); 
         command.Parameters.Add(new OleDbParameter("@EndRecordNumber", StartRecordNumber + NumberOfRecordsToRetrieve)); 

         connection.Open(); 
         OleDbDataReader reader = command.ExecuteReader(); 

          EndOfFile = true;
          while (reader.Read()) 
          { 
               EndOfFile = false

               //Retrieve records here and do whatever process you wish to do
           } 
           reader.Close(); 

           StartRecordNumber += NumberOfRecordsToRetrieve;
     } 
}

Respondido 01 ago 12, 15:08

But there is a small problem.When there are inner joins the recno() doesn't seem to be working. - Arjun

@arjun Could you provide an example of how you are attempting to use the RECNO() in an inner join? - Gen S

string queryString = "SELECT OrderID, CustomerID FROM Orders WHERE ORDERID >= @StartOrderID AND ORDERID <= @EndOrderID";

    using (OleDbConnection connection = new OleDbConnection(connectionString))
    {
        OleDbCommand command = new OleDbCommand(queryString, connection);
        command.Parameters.Add(new OleDbParameter("@StartOrderID", "PASS THE VALUE HERE"));
        command.Parameters.Add(new OleDbParameter("@EndOrderID", "PASS THE VALUE HERE"));

        connection.Open();
        OleDbDataReader reader = command.ExecuteReader();

        while (reader.Read())
        {
//Retrieve records here
        }
        reader.Close();
    }

Respondido 31 Jul 12, 10:07

most of my tables don't have primary key ids.Can we not use something like row_number() in the query like in sql server. - Arjun

@arjun in your case yes you can - SombreroSoft

@arjun I am mid of something please can you wait for 15 minutes - SombreroSoft

@arjun you will need to modify you sql query to use ROW_NUM look at the example here msdn.microsoft.com/en-us/library/ms186734.aspx - SombreroSoft

I was talking about visual fox pro not sql server - Arjun

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.