|
阅读:1507回复:1
ArcEngine数据删除几种方法和性能比较<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> |
|
|
|
1楼#
发布于:2009-06-30 08:54
我写的,转载怎么没有我的信息
|
|