Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

up vote 6 down vote accepted

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);
}
share|improve this answer
add comment

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);
    }
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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