Will Read

Will Read

  • NA
  • 13
  • 15.3k

Slow Array Parsing (using Lists)

Nov 24 2010 7:08 AM
Hi All,

I'm loading in some data from an Oracle DB and finding it's reaaaaaally slow. It's about 65,000 customers I'm loading in and it takes about 30 mins to run.

I've tried a few different array types and settled on List (I read that the strongly typed collection was one of the best), but it's bloody awful.

Any ideas what I'm doing wrong?


<CODE>
     class Customer : IComparable
     {
         //create a constructor
         public Customer()
         {
 
         }
 
         public string Code;
         public string Name;
         public string GenericPriceListName;
         public string GenericPriceListType;
         public string PriceList;
         public string DiscountList;
         public string ExceptionList;
         public string PromotionList;
 
 
         // implement IComparable interface
         public int CompareTo(object obj)
         {
             if (obj is Customer)
             {
                 return this.Code.CompareTo((obj as Customer).Code);  // compare user names
             }
             throw new ArgumentException("Object is not a Customer");
         }
 
    }
    
 class Program
 {
 
  private static List<Customer> GetCustomerList(OleDbConnection myOleDbConnection)
        {
            OleDbCommand myOleDbCommand;
            OleDbDataReader myOleDbDataReader;
            List<Customer> listOfCustomers = new List<Customer>();

            myOleDbCommand = myOleDbConnection.CreateCommand();

            StringBuilder sqlStatement = new StringBuilder();
            sqlStatement.Append("Select * from Customers");


            myOleDbCommand.CommandText = sqlStatement.ToString();


            myOleDbDataReader = myOleDbCommand.ExecuteReader();


            

            while (myOleDbDataReader.Read())
            {

                Customer currentCustomer = new Customer();
                currentCustomer.Code = myOleDbDataReader.GetString(0);
                currentCustomer.Name = myOleDbDataReader.GetString(1);
                currentCustomer.GenericPriceListName = myOleDbDataReader.GetString(2);
                currentCustomer.GenericPriceListType = myOleDbDataReader.GetString(3);

                listOfCustomers.Add(currentCustomer);

                Console.WriteLine(string.Format("Extracting account {0}", currentCustomer.Name));
            }

            myOleDbDataReader.Close();
            myOleDbCommand.Dispose();


            return listOfCustomers;
        }
}
</CODE>




Answers (1)