这是在网上无意中看到的方法, 与之前使用的删除要素方法相比, 使用ExecuteSQL删除最快,数据库的效率最高。
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
Private Sub DeleteFeature()sub DeleteFeature(byval pFeatureClass as IFeatureClass)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
Dim pDataset as IDataset
Set pDataset=pFeatureClass
pDataset.Workspace.ExecuteSQL("delete from " + PFeatureclass.AliasName + " where objectid=***)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
End Sub
不過某些情況下可能不支持IWorkspace.ExecuteSQL這個方法,所以使用前最好先make sure這個方法在當前workspace下是否被支持. 在EDN里對IWorkspace.ExecuteSQL方法的注釋有這樣一段話:
To determine if a workspace supports the ExecutesSQL method, an application can check the value of the canExecuteSQLworkspace property via the optional IWorkspaceProperties interface. In general, this method is only supported on local and remote database workspaces(這里指的是MDB,SDE database這些,而ShapeFile, CAD, Coverage的workspace就不支持這個方法的吧)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
Public Sub UsingExecuteSQL()Sub UsingExecuteSQL(pWorkspace as IWorkspace,pFeatureclass as IFeatureClass, value as string)
'-------------------------------------------------
' If IWorkspace.ExecuteSQL is supported, using it
'-------------------------------------------------
Dim pWorkspaceProperties As IWorkspaceProperties
Set pWorkspaceProperties = pWorkspace
Dim pWSProperty As IWorkspaceProperty
Set pWSProperty = pWorkspaceProperties.Property(esriWorkspacePropertyGroup, esriWorkspacePropCanExecuteSQL)
If pWSProperty.IsSupported = True Then
pWorkspace.ExecuteSQL "Update " & pFeatureclass.AliasName & " set Layer='" & value & "'"
End If
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
End Sub
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)