[GIS] How to get all OIDs from a table

arccatalogarcmaparcobjectsc

I have table which I need to get all the OID's from it.

I tried this code :

List<int> OIDList = new List<int>();
IQueryFilter queryFilter = new QueryFilterClass();
queryFilter.SubFields = "OBJECTID";

for (int i = 1; i <= table.RowCount(queryFilter); i++) {
    OIDList.Add(i);
}

But the problem is there is some values were skipped, e.g. the table contains 60 row but the OID for the last row is 100.

In the code above, I can not catch any OID more than 60.

How can I get all the OIDs?

Best Answer

I would use the ITable interface if it is a standalone table.

List<int> OIDList = new List<int>();
ICursor pCursor = pTable.Search(null,False);

while((pRow = pCursor.NextRow) != null))
{
    OIDList.Add(pRow.OID);
}
Related Question