首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 企业软件 > 行业软件 >

急当拷贝一个要素时,为什么在vb.net中会出错,而在VB中不出错?该如何解决

2012-02-27 
急急,当拷贝一个要素时,为什么在vb.net中会出错,而在VB中不出错?privatesubcopyAttribute(byrefpTargetCla

急急,当拷贝一个要素时,为什么在vb.net中会出错,而在VB中不出错?
private   sub   copyAttribute(byref     pTargetClass   as   IFeatureClass,byval   pSourceFeature   as   IFeature)  
    Dim   i   As   Long
      Dim   lValueIndex   As   Long
    Dim   lNewIndex   As   Long
    Dim   pBuffer   As   IFeatureBuffer
    Dim   pInsert   As   IFeatureCursor
    Set   pInsert   =   pTargetClass.Insert(True)
   
        Set   pBuffer   =   pTargetClass.CreateFeatureBuffer
        pBuffer.Shape   =   pSourceFeature.ShapeCopy
       
        For   i   =   0   To   pSourceFeature.Fields.FieldCount   -   1
            If   ((pSourceFeature.Fields.Field(i).Type   <>   esriFieldTypeOID)   And   _
                    (pSourceFeature.Fields.Field(i).Type   <>   esriFieldTypeGeometry))   Then
                lValueIndex   =   pSourceFeature.Fields.FindField(pSourceFeature.Fields.Field(i).Name)
                lNewIndex   =   pBuffer.Fields.FindField(pSourceFeature.Fields.Field(i).Name)
               
                pBuffer.Value(lNewIndex)   =   pFeature.Value(lValueIndex) '当某些字段值为空时,出错
            End   If
        Next   i
       
        pInsert.InsertFeature   pBuffer

    pInsert.Flush

end   sub

[解决办法]
可以用IIf函数做个判断阿
pBuffer.Value(lNewIndex) =IIf (pFeature.Value(lValueIndex) is null or pFeature.Value(lValueIndex) = "" ,null,pFeature.Value(lValueIndex) )

热点排行