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 String FeatOID = "SDE_OBJECT_ID = '" & pFeature.OID & "'"
Dim FeatOID As String FeatOID = "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:
Private Sub CommandButton1_Click() Dim pMxDoc As IMxDocument Set pMxDoc = ThisDocument Dim pMap As IMap Set pMap = pMxDoc.FocusMap Dim pFeatureLayer As IFeatureLayer Set pFeatureLayer = pMap.Layer(2) Dim pFeatureSelection As IFeatureSelection Set pFeatureSelection = pFeatureLayer Dim pFeatureCursor As IFeatureCursor pFeatureSelection.SelectionSet.Search Nothing, False, pFeatureCursor Dim pFeature As IFeature Set pFeature = pFeatureCursor.NextFeature Do 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 Loop Dim pTableCollection As ITableCollection Set pTableCollection = pMap Dim pTable As ITable For i = 0 To pTableCollection.TableCount - 1 'i am selecting the Oracle table Set pTable = pTableCollection.Table(i) Next i Dim FeatOID As Long FeatOID = pFeature.OID Dim Query As String Query = "SDE_OBJECT_ID = '" & FeatOID & "'" Dim pQueryFilter As IQueryFilter Set pQueryFilter = New QueryFilter pQueryFilter.WhereClause = Query Dim pCursor As ICursor Set pCursor = pTable.Search(pQueryFilter, False) Dim pRow As IRow Set pRow = pCursor.NextRow While 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 Wend End Sub