2

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?

2 Answers 2

7

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);
}
2

Thanks a lot, i make some changes on the code now it's work properly.

List<int> OIDList = new List<int>();
IQueryFilter queryFilter = new QueryFilterClass();
    queryFilter.SubFields = "OBJECTID";
    ICursor pCursor = pTable.Search(queryFilter, false);
    IRow pRow = null;
    while((pRow = pCursor.NextRow) != null))
    {
        OIDList.Add(pRow.OID);
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.