Matching OBJECTID with a value at VBA in Arcmap

المشرف العام

Administrator
طاقم الإدارة
I got a building layer. And i got a table that contains 2 fields named SDE_OBJECT_ID and DOOR_NO. This table is not spatial table, it's Oracle table which i can join with my building layer if i want and i can use building layer's OID field with this table's "SDE_OBJECT_ID" field. What i try to do is to select a building with my mouse and then running this tool to show all the door numbers that is located in this Oracle table. There can be 1+ door numbers so i am listing them in my listbox as you can see.

The code works if i change

Dim FeatOID As StringFeatOID = "SDE_OBJECT_ID = '" & pFeature.OID & "'"to

Dim FeatOID As StringFeatOID = "SDE_OBJECT_ID = 48565"i mean it works if i type an OBJECTID number but it doesnt work while i try to grap the OBJECTID of the selected feature.

I also tried to do this

pQueryFilter.WhereClause = "SDE_OBJECT_ID = '" + pFeature.Value(pFeature.Fields.FindField("OBJECTID")) +"' "but it doesn't work...

Here is my code, thank you in advance!

Private Sub CommandButton1_Click()Dim pMxDoc As IMxDocumentSet pMxDoc = ThisDocumentDim pMap As IMapSet pMap = pMxDoc.FocusMapDim pFeatureLayer As IFeatureLayerSet pFeatureLayer = pMap.Layer(2)Dim pFeatureSelection As IFeatureSelectionSet pFeatureSelection = pFeatureLayerDim pFeatureCursor As IFeatureCursorpFeatureSelection.SelectionSet.Search Nothing, False, pFeatureCursorDim pFeature As IFeatureSet pFeature = pFeatureCursor.NextFeatureDo Until pFeature Is Nothing'MsgBox pFeature.Value(pFeature.Fields.FindField("OBJECTID")) 'it works, shows the OID of the selected feature MsgBox pFeature.OID 'it works too Set pFeature = pFeatureCursor.NextFeature LoopDim pTableCollection As ITableCollectionSet pTableCollection = pMapDim pTable As ITableFor i = 0 To pTableCollection.TableCount - 1 'i am selecting the Oracle tableSet pTable = pTableCollection.Table(i)Next iDim FeatOID As LongFeatOID = pFeature.OIDDim Query As StringQuery = "SDE_OBJECT_ID = '" & FeatOID & "'"Dim pQueryFilter As IQueryFilterSet pQueryFilter = New QueryFilterpQueryFilter.WhereClause = QueryDim pCursor As ICursorSet pCursor = pTable.Search(pQueryFilter, False)Dim pRow As IRowSet pRow = pCursor.NextRowWhile Not pRow Is Nothing 'MsgBox pRow.Value(pRow.Fields.FindField("DOOR_NO")) ListBox1.AddItem (pRow.Value(pRow.Fields.FindField("DOOR_NO"))) Set pRow = pCursor.NextRow WendEnd Sub

أكثر...
 
أعلى