'向Sde空间数据库中插入一条记录,并返回其ObjectId。
Public Shared Function InsertFeatureToSde(ByVal pFeatureGeometry As IGeometry, ByVal FeatureAttributes As Collection, ByVal strSDETableName As String, _
Optional ByVal txtLog As System.Windows.Forms.TextBox = Nothing, _
Optional ByVal Flag As Integer = -1, _
Optional ByVal ds As DataSet = Nothing, _
Optional ByVal pShapeFileds As Collection = Nothing) As Long
On Error GoTo errhdl
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim pFeatureClass As IFeatureClass, pFeatureCursor As IFeatureCursor, pFeatureBuffer As IFeatureBuffer, pFeatureFields As IFields, pFeatureField As IField
Dim i As Integer, m As Integer, strFieldName As String, strFieldVale As String, boolNull As Boolean = False
Dim FeatureObjectID As Long
Dim ErrSelfIntersect As Integer = 0
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Select Case Flag
Case -1, 2
strSDETableName = "SDE." ; strSDETableName
pFeatureClass = pFeatureClassCollection.Item(strSDETableName)
Case 1, 3
pFeatureClass = pFeatureWorkspace.OpenFeatureClass(strSDETableName)
End Select
If pFeatureClass Is Nothing Then
txtLog.Text = txtLog.Text ; Trim(FeatureAttributes.Item("UCODE")) ; ".shp:" ; "Shape文件对应空间图层" ; Mid(strSDETableName, 5) ; "没有找到" ; vbCrLf
pFeatureClass = Nothing
Exit Function
End If
pFeatureCursor = pFeatureClass.Insert(True)
pFeatureBuffer = pFeatureClass.CreateFeatureBuffer
pFeatureFields = pFeatureClass.Fields
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Select Case Flag
Case -1, 1, 3
For i = 0 To pFeatureFields.FieldCount - 1
DoEvents()
boolNull = False
pFeatureField = pFeatureFields.Field(i)
If pFeatureField.Type = esriFieldType.esriFieldTypeGeometry Then
pFeatureBuffer.Value(i) = pFeatureGeometry
Else
strFieldName = pFeatureField.Name
strFieldVale = FeatureAttributes.Item(strFieldName)
If Not boolNull And Not UCase(Trim(strFieldVale)) = "NUL" Then
If pFeatureField.Type = esriFieldType.esriFieldTypeString Then
If strFieldName = "MAXH" Then
If CDbl(Trim(strFieldVale)) <> 0 Then
pFeatureBuffer.Value(i) = Trim(strFieldVale)
End If
Else
pFeatureBuffer.Value(i) = Trim(strFieldVale)
End If
End If
If pFeatureField.Type = esriFieldType.esriFieldTypeDouble Then
pFeatureBuffer.Value(i) = CDbl(Trim(strFieldVale))
End If
End If
End If
Next
Case 2
'赋FeatureBuffer图形数据
strFieldName = pFeatureClass.ShapeFieldName
m = pFeatureBuffer.Fields.FindField(strFieldName)
If Not m = -1 Then
pFeatureBuffer.Value(m) = pFeatureGeometry
End If
'赋FeatureBuffer属性数据
For i = 1 To pShapeFileds.Count
strFieldName = UCase(Trim(pShapeFileds.Item(i)))
m = pFeatureBuffer.Fields.FindField(strFieldName)
If Not m = -1 Then
boolNull = False
strFieldVale = FeatureAttributes.Item(strFieldName)
If Not boolNull And Not UCase(Trim(strFieldVale)) = "NUL" Then
If pFeatureBuffer.Fields.Field(m).Type = esriFieldType.esriFieldTypeString Then
pFeatureBuffer.Value(m) = Trim(strFieldVale)
End If
If pFeatureBuffer.Fields.Field(m).Type = esriFieldType.esriFieldTypeDouble Then
If strFieldName = "SYMBANGLE" Then
pFeatureBuffer.Value(m) = CDbl(Trim(strFieldVale)) + 90
Else
pFeatureBuffer.Value(m) = CDbl(Trim(strFieldVale))
End If
End If
End If
Else
If Not strFieldName = "NAME" Then
txtLog.Text = txtLog.Text ; Trim(FeatureAttributes.Item("UCODE")) ; ".shp:找不到Sde空间图层属性字段" ; strFieldName ; vbCrLf
End If
End If
Next
If Not pFeatureBuffer.Fields.FindField("UCODE") = -1 Then pFeatureBuffer.Value(pFeatureBuffer.Fields.FindField("UCODE")) = Trim(FeatureAttributes.Item("UCODE"))
If Not pFeatureBuffer.Fields.FindField("NAME") = -1 Then pFeatureBuffer.Value(pFeatureBuffer.Fields.FindField("NAME")) = Trim(FeatureAttributes.Item("NAME"))
If Not pFeatureBuffer.Fields.FindField("NFCODE") = -1 Then pFeatureBuffer.Value(pFeatureBuffer.Fields.FindField("NFCODE")) = Trim(FeatureAttributes.Item("NFCODE"))
End Select
FeatureObjectID = pFeatureCursor.InsertFeature(pFeatureBuffer)
If Flag = 3 Then pFeatureCursor.Flush()
Return FeatureObjectID
代码没有经过整理,中间可能有比较多关于业务的内容,不过关于接口方面的东东楼主还是可以参考一下