ExecuteSQL删除数据
这是在网上无意中看到的方法, 与之前使用的删除要素方法相比, 使用ExecuteSQL删除最快,数据库的效率最高。
Private sub DeleteFeature(byval pFeatureClass as IFeatureClass)
Dim pDataset as IDataset
Set pDataset=pFeatureClass
pDataset.Workspace.ExecuteSQL("delete from " + PFeatureclass.AliasName + " where objectid=***)
End Sub
Dim pDataset as IDataset
Set pDataset=pFeatureClass
pDataset.Workspace.ExecuteSQL("delete from " + PFeatureclass.AliasName + " where objectid=***)
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就不支持這個方法的吧)
Public 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
End Sub
'-------------------------------------------------
' 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
End Sub
-----------------------------------------------------------
佛对我说:你心里有尘。我用力的拭擦。