ArcEngine数据删除几种方法和性能比较 转载的

时间:2022-02-07 20:20:29

1、IFeatureCursor 游标查询后,遍历删除

2、更新游标删除IFeatureCursor.DeleteFeature()

3、ITable.DeleteSearchedRows删除

4、 IDataset.Workspace.ExecuteSQL

 

一、  几种删除方法代码

1.  查询结果中删除

  private void Delete1(IFeatureClass PFeatureclass)
        {
            IQueryFilter pQueryFilter = new QueryFilterClass();
            pQueryFilter.WhereClause = "objectID<=" + DeleteNum;
            IFeatureCursor pFeatureCursor = PFeatureclass.Search(pQueryFilter, false);            IFeature pFeature = pFeatureCursor.NextFeature();
            while (pFeature != null)
            {
                pFeature.Delete();
                pFeature = pFeatureCursor.NextFeature();
            }
            System.Runtime.InteropServices.Marshal.ReleaseComObject(pQueryFilter);
        }

2.  更新游标删除
private void Delete2(IFeatureClass PFeatureclass)
        {
            IQueryFilter pQueryFilter = new QueryFilterClass();
            pQueryFilter.WhereClause = "objectID<=" + DeleteNum;
            IFeatureCursor pFeatureCursor = PFeatureclass.Update(pQueryFilter, false);
            IFeature pFeature = pFeatureCursor.NextFeature();
            while (pFeature != null)
            {
                pFeatureCursor.DeleteFeature();
                pFeature = pFeatureCursor.NextFeature();
            }
            System.Runtime.InteropServices.Marshal.ReleaseComObject(pQueryFilter);
        }

3.  使用DeleteSearchedRows删除
private void Delete4(IFeatureClass PFeatureclass)
        {
            IQueryFilter pQueryFilter = new QueryFilterClass();
            pQueryFilter.WhereClause = "objectID<=" + DeleteNum;
            ITable pTable = PFeatureclass as ITable;
            pTable.DeleteSearchedRows(pQueryFilter);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(pQueryFilter);
        }