Optimum/best way to extract column data into a list?

256
2
02-05-2020 12:33 PM
GyanendraGurung
New Contributor III

Hi everyone,

I want to extract all the rows of a specific field in a given table. This is how I am doing it. 

  1. List<UInt32> outputList= new List<UInt32>();                 
  2.   
  3. // Query table    
  4. await QueuedTask.Run(() => {    
  5.     using (Geodatabase curGDB = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(selectedGDB))))    
  6.     using (Table table = curGDB.OpenDataset<Table>(selectedTable))    
  7.     {      
  8.         QueryFilter qF = new QueryFilter    
  9.         {    
  10.             WhereClause = "OBJECTID > 0"    
  11.         };      
  12.         using (RowCursor rc = table.Search(qF, false))    
  13.         {    
  14.             while (rc.MoveNext())    
  15.             {    
  16.                 using (Row row = rc.Current)    
  17.                 {    
  18.                     outputList.Add(Convert.ToUInt32(row[selectedField]));    
  19.                 }    
  20.             }    
  21.         }      
  22.     }      
  23. }); 

My questions is: Is this a good way? Do I have to use "QueryFilter" and move through each row? Is there a better/optimum way? 

Many thanks in advance.  

0 Kudos
2 Replies
RichRuh
Esri Regular Contributor

Yes, this is the best way.  I would recommend the following small changes.

  • Remove the WhereClause (which isn't really doing anything, since ObjectIDs should always be greater than zero)
  • Use the Subfields property to reduce the amount of data being read from the database
  • On the call to Table.Search, set the useRecyclingCursor property to True

--Rich

GyanendraGurung
New Contributor III

Hi Rich, 

Thank you very much for your kind and prompt reply. I will try to use the Subfields property and optimize my code. I shall post it as soon as I get time to code it. 

- Kenny

0 Kudos