ArcGIS Engine 删除数据方法(转)

 ArcEngine,C#数据删除几种方法和性能比较
一、  几种删除方法代码
1.  查询结果中删除
  1. private void Delete1(IFeatureClass PFeatureclass)

  2. {

  3. IQueryFilter pQueryFilter = new QueryFilterClass();

  4. pQueryFilter.WhereClause = "objectID<=" + DeleteNum;

  5. IFeatureCursor pFeatureCursor = PFeatureclass.Search(pQueryFilter, false); IFeature pFeature = pFeatureCursor.NextFeature();

  6. while (pFeature != null)

  7. {

  8. pFeature.Delete();

  9. pFeature = pFeatureCursor.NextFeature();

  10. }

  11. System.Runtime.InteropServices.Marshal.ReleaseComObject(pQueryFilter);

  12. }
复制代码


2.  更新游标删除
  1. private void Delete2(IFeatureClass PFeatureclass)

  2. {

  3. IQueryFilter pQueryFilter = new QueryFilterClass();

  4. pQueryFilter.WhereClause = "objectID<=" + DeleteNum;

  5. IFeatureCursor pFeatureCursor = PFeatureclass.Update(pQueryFilter, false);

  6. IFeature pFeature = pFeatureCursor.NextFeature();

  7. while (pFeature != null)

  8. {

  9. pFeatureCursor.DeleteFeature();

  10. pFeature = pFeatureCursor.NextFeature();

  11. }

  12. System.Runtime.InteropServices.Marshal.ReleaseComObject(pQueryFilter);



  13. }
复制代码


3.  使用DeleteSearchedRows删除
  1. private void Delete4(IFeatureClass PFeatureclass)

  2. {

  3. IQueryFilter pQueryFilter = new QueryFilterClass();

  4. pQueryFilter.WhereClause = "objectID<=" + DeleteNum;

  5. ITable pTable = PFeatureclass as ITable;

  6. pTable.DeleteSearchedRows(pQueryFilter);

  7. System.Runtime.InteropServices.Marshal.ReleaseComObject(pQueryFilter);

  8. }
复制代码


4.  ExecuteSQL删除
  1. private void Delete4(IFeatureClass PFeatureclass)

  2. {

  3. IDataset pDataset = PFeatureclass as IDataset;

  4. pDataset.Workspace.ExecuteSQL("delete from " + PFeatureclass.AliasName + " where objectid<=" + DeleteNum);

  5. }
复制代码


二、  测试性能和比较
1、       相同的数据条件,删除2000条记录
2、       测试代码
  1. IFeatureLayer pFeatureLayer = axMapControl1.Map.get_Layer(0) as IFeatureLayer;

  2. IFeatureClass PFeatureClass = pFeatureLayer.FeatureClass;

  3. System.Diagnostics.Stopwatch MyWatch = new System.Diagnostics.Stopwatch();

  4. MyWatch.Start();

  5. Delete1(PFeatureClass)

  6. //Delete2(PFeatureClass);

  7. //Delete3(PFeatureClass);

  8. //Delete4(PFeatureClass);

  9. //Delete5(PFeatureClass);

  10. MyWatch.Stop();

  11. MessageBox.Show("删除时间:" + MyWatch.ElapsedMilliseconds.ToString() + "毫秒");
复制代码


3、测试情况
    测试方法
    第一次时间(单位ms)
    第一次时间(单位ms)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值