I am trying to build a new table based on an existing table. The existing table is actually the attribute table for a road centerline featureclass. What I'm wanting to do is to take the existing road centerline featureclass, sort it, then loop through the tablesort object and write those rows to a new table. So far I've been able to create the tablesort object and I've been able to create a new table with exactly the same fields as the original featureclass (and thus the tablesort object as well), but I'm stuck on how to write the rows from the tablesort object to the new table. I realize I'll need an insert cursor at some point, but I don't know the best way to do this. Could somebody give me a few suggestions on where to start or what interfaces to look at? Can what I want even be done?

The code snippet below should get you started, you need to look at IFeatureClass, IFeatureBuffer and IFeatureCursor. The snippet assumes that pFtrCls has already been set to the output featureclass.

Hope that helps,
Miles

Dim pFtrCsr As IFeatureCursor
Dim pFtrBfr As IFeatureBuffer
' Create a feature buffer, used to temporarily store
' feature data before it is inserted into a featureclass
Set pFtrBfr = pFtrCls.CreateFeatureBuffer
' Create an Insert FeatureCursor, specifying
'that we'll be using a FeatureBuffer
Set pFtrCsr = pFtrCls.Insert(True)
' Add some values to the featurebuffers fields
' This featurebuffer acts just like a feature
' but we can only write to it, not read from it
pFtrBfr.Value(2) = vSomeValue ' a value for the 3rd field
Set pFtrBfr.Shape = pSomeGeometry ' the new geometry for the feature
' Insert this into the featureclass using the featurecursor
pFtrCsr.InsertFeature pFtrBfr
' We can now repopulate the fields of the feature buffer and
' continue inserting as above

The problem is that you're code is trying to copy the old OID to the new record (which can't be done as this is a non-editable field and it's value is automatically generated by Arc). You need to put in a check to see if the field is editable, if it's not then don't assign a value to it, you can use IField.Editable for this.

Also, I noticed a couple of problems with your code, you're creating an empty polyline to store in the featureclass, although this may work, you wont be able to see anything in your map! The other thing is that you're assigning this geometry inside the fields loop, it only needs to be done once, outside the loop.

Thanks for your help. I need to reevaluate what I want to do. I don't actually need any geometry data in my output table. In a nutshell, I want to take the table of a featureclass, sort it, and then re-create the sorted table in a new standalone table. No spatial or geomterical requirements whatsoever, I strictly want to work with attribution that's permanently sorted. I may be posting a new topic shortly. Thanks again for the help, I'll be saving this bit of code for another day. :)

1. Make sure you're output table is a .dbf file (it will still be an ITable in ArcObjects) and doesn't contain a "Shape" field.

2. When you output the fields to the new table make sure you don't output the OID field or the Shape field. These can easily be checked via the IFeatureClass.OIDFieldName and IFeatureClass.ShapeFieldName.

If this isn't clear enough then post a link to your new thread and I'll take a look at it.