cl991036
管理员
管理员
  • 注册日期2003-07-25
  • 发帖数5917
  • QQ14265545
  • 铜币29669枚
  • 威望217点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • GIS帝国铁杆
阅读:1507回复:1

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

楼主#
更多 发布于:2009-06-23 15:13

<p  align="left"><strong style="line-height: normal ! important;">一、</strong><strong style="line-height: normal ! important;"><font style="line-height: normal ! important;" face="Times New Roman">  </font></strong><strong style="line-height: normal ! important;">几种删除方法代码</strong><p ></p></p>
<p  align="left"><strong style="line-height: normal ! important;">1.</strong><strong style="line-height: normal ! important;"><font style="line-height: normal ! important;" face="Times New Roman">  </font></strong><strong style="line-height: normal ! important;">查询结果中删除</strong><p ></p></p>
<p  align="left">  private void Delete1(IFeatureClass PFeatureclass)<p ></p></p>
<p  align="left">        {<p ></p></p>
<p  align="left">            IQueryFilter pQueryFilter = new QueryFilterClass();<p ></p></p>
<p  align="left">            pQueryFilter.WhereClause = "objectID<=" + DeleteNum;<p ></p></p>
<p  align="left">            IFeatureCursor pFeatureCursor = PFeatureclass.Search(pQueryFilter, false);            IFeature pFeature = pFeatureCursor.NextFeature();<p ></p></p>
<p  align="left">            while (pFeature != null)<p ></p></p>
<p  align="left">            {<p ></p></p>
<p  align="left">                pFeature.Delete();<p ></p></p>
<p  align="left">                pFeature = pFeatureCursor.NextFeature();<p ></p></p>
<p  align="left">            }<p ></p></p>
<p  align="left">            System.Runtime.InteropServices.Marshal.ReleaseComObject(pQueryFilter);<p ></p></p>
<p  align="left">        }<p ></p></p>
<p  align="left"><strong style="line-height: normal ! important;">2.</strong><strong style="line-height: normal ! important;"><font style="line-height: normal ! important;" face="Times New Roman">  </font></strong><strong style="line-height: normal ! important;">更新游标删除</strong><p ></p></p>
<p  align="left">private void Delete2(IFeatureClass PFeatureclass)<p ></p></p>
<p  align="left">        {<p ></p></p>
<p  align="left">            IQueryFilter pQueryFilter = new QueryFilterClass();<p ></p></p>
<p  align="left">            pQueryFilter.WhereClause = "objectID<=" + DeleteNum;<p ></p></p>
<p  align="left">            IFeatureCursor pFeatureCursor = PFeatureclass.Update(pQueryFilter, false);<p ></p></p>
<p  align="left">            IFeature pFeature = pFeatureCursor.NextFeature();<p ></p></p>
<p  align="left">            while (pFeature != null)<p ></p></p>
<p  align="left">            {<p ></p></p>
<p  align="left">                pFeatureCursor.DeleteFeature();<p ></p></p>
<p  align="left">                pFeature = pFeatureCursor.NextFeature();<p ></p></p>
<p  align="left">            }<p ></p></p>
<p  align="left">            System.Runtime.InteropServices.Marshal.ReleaseComObject(pQueryFilter);<p ></p></p>
<p  align="left"><font style="line-height: normal ! important;" face="Times New Roman"> <p ></p></font></p>
<p  align="left">        }<p ></p></p>
<p  align="left"><strong style="line-height: normal ! important;">3.</strong><strong style="line-height: normal ! important;"><font style="line-height: normal ! important;" face="Times New Roman">  </font></strong><strong style="line-height: normal ! important;">使用DeleteSearchedRows删除</strong><p ></p></p>
<p  align="left">private void Delete4(IFeatureClass PFeatureclass)<p ></p></p>
<p  align="left">        {<p ></p></p>
<p  align="left">            IQueryFilter pQueryFilter = new QueryFilterClass();<p ></p></p>
<p  align="left">            pQueryFilter.WhereClause = "objectID<=" + DeleteNum;<p ></p></p>
<p  align="left">            ITable pTable = PFeatureclass as ITable;<p ></p></p>
<p  align="left">            pTable.DeleteSearchedRows(pQueryFilter);<p ></p></p>
<p  align="left">            System.Runtime.InteropServices.Marshal.ReleaseComObject(pQueryFilter);<p ></p></p>
<p  align="left">        }<p ></p></p>
<p  align="left"><strong style="line-height: normal ! important;"> </strong><p ></p></p>
<p  align="left"><strong style="line-height: normal ! important;">4.</strong><strong style="line-height: normal ! important;"><font style="line-height: normal ! important;" face="Times New Roman">  </font></strong><strong style="line-height: normal ! important;">ExecuteSQL</strong><strong style="line-height: normal ! important;">删除</strong><p ></p></p>
<p  align="left">private void Delete4(IFeatureClass PFeatureclass)<p ></p></p>
<p  align="left">        {<p ></p></p>
<p  align="left">            IDataset pDataset = PFeatureclass as IDataset;<p ></p></p>
<p  align="left">            pDataset.Workspace.ExecuteSQL("delete from " + PFeatureclass.AliasName + " where objectid<=" + DeleteNum);<p ></p></p>
<p  align="left">        }<p ></p></p>
<p  align="left"><strong style="line-height: normal ! important;">二、</strong><strong style="line-height: normal ! important;"><font style="line-height: normal ! important;" face="Times New Roman">  </font></strong><strong style="line-height: normal ! important;">测试性能和比较</strong><p ></p></p>
<p  align="left"><strong style="line-height: normal ! important;">1</strong><strong style="line-height: normal ! important;">、</strong><strong style="line-height: normal ! important;"><font style="line-height: normal ! important;" face="Times New Roman">       </font></strong><strong style="line-height: normal ! important;">相同的数据条件,删除2000条记录</strong><p ></p></p>
<p  align="left"><strong style="line-height: normal ! important;">2</strong><strong style="line-height: normal ! important;">、</strong><strong style="line-height: normal ! important;"><font style="line-height: normal ! important;" face="Times New Roman">       </font></strong><strong style="line-height: normal ! important;">测试代码</strong><p ></p></p>
<p  align="left">IFeatureLayer pFeatureLayer = axMapControl1.Map.get_Layer(0) as IFeatureLayer;<p ></p></p>
<p  align="left">            IFeatureClass PFeatureClass = pFeatureLayer.FeatureClass;<p ></p></p>
<p  align="left">            System.Diagnostics.Stopwatch MyWatch = new System.Diagnostics.Stopwatch();<p ></p></p>
<p  align="left">            MyWatch.Start();<p ></p></p>
<p  align="left">            Delete1(PFeatureClass)<p ></p></p>
<p  align="left">            //Delete2(PFeatureClass);<p ></p></p>
<p  align="left">            //Delete3(PFeatureClass);<p ></p></p>
<p  align="left">            //Delete4(PFeatureClass);<p ></p></p>
<p  align="left">            //Delete5(PFeatureClass);<p ></p></p>
<p  align="left">            MyWatch.Stop();<p ></p></p>
<p  align="left">            MessageBox.Show("删除时间:" + MyWatch.ElapsedMilliseconds.ToString() + "毫秒");<p ></p></p>
<p  align="left"><strong style="line-height: normal ! important;">3</strong><strong style="line-height: normal ! important;">、</strong><strong style="line-height: normal ! important;"><font style="line-height: normal ! important;" face="Times New Roman">       </font></strong><strong style="line-height: normal ! important;">测试情况</strong><p ></p></p>

<table  border="1" cellpadding="0" cellspacing="0">
    
        <tr >
            <td  valign="top" width="175">
            <p  align="center"><strong style="line-height: normal ! important;">测试方法</strong><p ></p></p>
            </td>
            <td  valign="top" width="191">
            <p  align="center"><strong style="line-height: normal ! important;">第一次时间(单位ms)</strong><p ></p></p>
            </td>
            <td  valign="top" width="169">
            <p  align="center"><strong style="line-height: normal ! important;">第一次时间(单位ms)</strong><p ></p></p>
            </td>
        </tr>
        <tr >
            <td  valign="top" width="175">
            <p  align="center"><strong style="line-height: normal ! important;">1</strong><p ></p></p>
            </td>
            <td  valign="top" width="191">
            <p  align="center">5214ms<p ></p></p>
            </td>
            <td  valign="top" width="169">
            <p  align="center">5735ms<p ></p></p>
            </td>
        </tr>
        <tr >
            <td  valign="top" width="175">
            <p  align="center"><strong style="line-height: normal ! important;">2</strong><p ></p></p>
            </td>
            <td  valign="top" width="191">
            <p  align="center">299ms<p ></p></p>
            </td>
            <td  valign="top" width="169">
            <p  align="center">290Ms<p ></p></p>
            </td>
        </tr>
        <tr >
            <td  valign="top" width="175">
            <p  align="center"><strong style="line-height: normal ! important;">3</strong><p ></p></p>
            </td>
            <td  valign="top" width="191">
            <p  align="center">59ms<p ></p></p>
            </td>
            <td  valign="top" width="169">
            <p  align="center">28ms<p ></p></p>
            </td>
        </tr>
        <tr >
            <td  valign="top" width="175">
            <p  align="center"><strong style="line-height: normal ! important;">4</strong><p ></p></p>
            </td>
            <td  valign="top" width="191">
            <p  align="center">26ms<p ></p></p>
            </td>
            <td  valign="top" width="169">
            <p  align="center">26ms<p ></p></p>
            </td>
        </tr>
    </table>
    
    <p  align="left"><strong style="line-height: normal ! important;">三、</strong><strong style="line-height: normal ! important;"><font style="line-height: normal ! important;" face="Times New Roman">  </font></strong><strong style="line-height: normal ! important;">结论</strong><p ></p></p>
    <p  align="left"><strong style="line-height: normal ! important;">1</strong><strong style="line-height: normal ! important;">、</strong><strong style="line-height: normal ! important;"><font style="line-height: normal ! important;" face="Times New Roman">         </font></strong><strong style="line-height: normal ! important;">使用ExecuteSQL删除最快,数据库的效率最高。</strong><p ></p></p>
    <p  align="left"><strong style="line-height: normal ! important;">2</strong><strong style="line-height: normal ! important;">、</strong><strong style="line-height: normal ! important;"><font style="line-height: normal ! important;" face="Times New Roman">         </font></strong><strong style="line-height: normal ! important;">DeleteSearchedRows</strong><strong style="line-height: normal ! important;">和ExecuteSQL属于批量删除,性能较优。</strong><p ></p></p>
    <p  align="left"><strong style="line-height: normal ! important;">3</strong><strong style="line-height: normal ! important;">、</strong><strong style="line-height: normal ! important;"><font style="line-height: normal ! important;" face="Times New Roman">         </font></strong><strong style="line-height: normal ! important;">查询结果中删除,速度最慢,如果你使用这种方法,建立你马上修改你的程序,因为你在浪费时间。</strong></p>
    
喜欢0 评分0
没钱又丑,农村户口。头可断,发型一定不能乱。 邮箱:gisempire@qq.com
yanleigis
路人甲
路人甲
  • 注册日期2003-12-13
  • 发帖数38
  • QQ
  • 铜币185枚
  • 威望0点
  • 贡献值0点
  • 银元0个
1楼#
发布于:2009-06-30 08:54
我写的,转载怎么没有我的信息
举报 回复(0) 喜欢(0)     评分
游客

返回顶部