//constructor for the class public clsCustomerCollection() { //object for the data connection clsDataConnection DB = new clsDataConnection(); //execute the stored procedure DB.Execute("sproc_tblCustomer_SelectAll"); //Populate the array list with the data table PopulateArray(DB); { //var for the index Int32 Index = 0; //var to store the record count Int32 RecordCount = 0; //get the count of records RecordCount = DB.Count; //while there are records to process while (Index < RecordCount) { //create a blank customer record clsCustomer ACustomer = new clsCustomer(); //read the fields from the current record ACustomer.CustomerNo = Convert.ToInt32(DB.DataTable.Rows[Index]["CustomerNo"]); ACustomer.Active = Convert.ToBoolean(DB.DataTable.Rows[Index]["Active"]); ACustomer.DateSold = Convert.ToDateTime(DB.DataTable.Rows[Index]["DateSold"]); ACustomer.FirstName = Convert.ToString(DB.DataTable.Rows[Index]["FirstName"]); ACustomer.Surname = Convert.ToString(DB.DataTable.Rows[Index]["Surname"]); ACustomer.Street = Convert.ToString(DB.DataTable.Rows[Index]["Street"]); ACustomer.PostCode = Convert.ToString(DB.DataTable.Rows[Index]["PostCode"]); ACustomer.Email = Convert.ToString(DB.DataTable.Rows[Index]["Email"]); ACustomer.HouseNo = Convert.ToString(DB.DataTable.Rows[Index]["HouseNo"]); ACustomer.PhoneNo = Convert.ToString(DB.DataTable.Rows[Index]["PhoneNo"]); ACustomer.Town = Convert.ToString(DB.DataTable.Rows[Index]["Town"]); //add the record to the private data member mCustomerList.Add(ACustomer); //point at the next record Index++; } } }
void PopulateArray(clsDataConnection DB) { Int32 Index = 0; Int32 RecordCount = 0; //var to store the record count RecordCount = DB.Count; mCustomerList = new List <clsCustomer>(); while (Index < RecordCount) { clsCustomer AnCustomer = new clsCustomer(); AnCustomer.Active = Convert.ToBoolean(DB.DataTable.Rows[Index]["Active"]); AnCustomer.CustomerNo = Convert.ToInt32(DB.DataTable.Rows[Index]["CustomerNo"]); AnCustomer.CustomerPostCode = Convert.ToString(DB.DataTable.Rows[Index]["CustomerPostCode"]); AnCustomer.PhoneNumber = Convert.ToInt32(DB.DataTable.Rows[Index]["PhoneNumber"]); AnCustomer.CustomerAddress = Convert.ToString(DB.DataTable.Rows[Index]["CustomerAddress"]); AnCustomer.CustomerName = Convert.ToString(DB.DataTable.Rows[Index]["CustomerName"]); mCustomerList.Add(AnCustomer); Index++; } }