Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim queryFilter As String = "Code = '" + ComboBox1.Text.Trim + "'" Dim table as ESRI.ArcGIS.Geodatabase.ITable = ????? MsgBox(PerformAttributeQuery(table, queryFilter)) End Sub Public Function PerformAttributeQuery(ByVal table As ESRI.ArcGIS.Geodatabase.ITable, ByVal whereClause As System.String) As ESRI.ArcGIS.Geodatabase.ICursor Dim queryFilter As ESRI.ArcGIS.Geodatabase.IQueryFilter = New ESRI.ArcGIS.Geodatabase.QueryFilterClass() queryFilter.WhereClause = whereClause Dim cursor As ESRI.ArcGIS.Geodatabase.ICursor = table.Search(queryFilter, False) Return cursor End Function
Solved! Go to Solution.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Try Dim pMap As IMap = My.ArcMap.Document.ActiveView Dim queryFilter As String = "FileNumber = '175980'" If PerformAttributeQuery(GetTable("CSJGISSDE.GISDATA.Subdivision_Plans_Table", pMap), queryFilter) Is Nothing Then MsgBox("Not Found") Else MsgBox("Found") End If Catch ex As Exception MsgBox("This action cannot be done. Save your project, then restart ArcMap.") End Try End Sub Public Function PerformAttributeQuery(ByVal table As ESRI.ArcGIS.Geodatabase.ITable, ByVal whereClause As System.String) As ESRI.ArcGIS.Geodatabase.ICursor Dim queryFilter As ESRI.ArcGIS.Geodatabase.IQueryFilter = New ESRI.ArcGIS.Geodatabase.QueryFilterClass() queryFilter.WhereClause = whereClause ' create the where clause statement ' query the table passed into the function and use a cursor to hold the results Dim cursor As ESRI.ArcGIS.Geodatabase.ICursor = table.Search(queryFilter, False) Return cursor End Function Private Function GetTable(ByVal InTableName As String, ByVal pMap As IMap) As ITable Dim pStTabColl As IStandaloneTableCollection pStTabColl = pMap For j As Integer = 0 To pStTabColl.StandaloneTableCount If (pStTabColl.StandaloneTable(j).Name = InTableName) Then Return pStTabColl.StandaloneTable(j) End If Next j Return Nothing End Function
Ken's code does find the table, but I'm having problem with what it returns to work with the PerformAttributeQuery snipet. This is what I have, which always end up to the Exception Error Message.:Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Try Dim pMap As IMap = My.ArcMap.Document.ActiveView Dim queryFilter As String = "FileNumber = '175980'" PerformAttributeQuery(GetTable("CSJGISSDE.GISDATA.Subdivision_Plans_Table", pMap), queryFilter) Catch ex As Exception MsgBox("This action cannot be done. Save your project, then restart ArcMap.") End Try End Sub Public Function PerformAttributeQuery(ByVal table As ESRI.ArcGIS.Geodatabase.ITable, ByVal whereClause As System.String) As ESRI.ArcGIS.Geodatabase.ICursor Dim queryFilter As ESRI.ArcGIS.Geodatabase.IQueryFilter = New ESRI.ArcGIS.Geodatabase.QueryFilterClass() queryFilter.WhereClause = whereClause ' create the where clause statement ' query the table passed into the function and use a cursor to hold the results Dim cursor As ESRI.ArcGIS.Geodatabase.ICursor = table.Search(queryFilter, False) Return cursor End Function Private Function GetTable(ByVal InTableName As String, ByVal pMap As IMap) As ITable Dim pStTabColl As IStandaloneTableCollection pStTabColl = pMap For j As Integer = 0 To pStTabColl.StandaloneTableCount If (pStTabColl.StandaloneTable(j).Name = InTableName) Then Return pStTabColl.StandaloneTable(j) End If Next j Return Nothing End Function
James, credit was given to Ken. Ken usually always figure out my problems, so I'm never shy to give him credits..haha! The WhereClause is fine. You need single quotes to query strings.
The code doesn't produces an error, it just act like the query is always true, even when it's not.
James, credit was given to Ken. Ken usually always figure out my problems, so I'm never shy to give him credits..haha! The WhereClause is fine. You need single quotes to query strings.
The code doesn't produces an error, it just act like the query is always true, even when it's not.
Public Function PerformAttributeQuery(ByVal table As ESRI.ArcGIS.Geodatabase.ITable, ByVal whereClause As System.String) As ESRI.ArcGIS.Geodatabase.ICursor Dim queryFilter As ESRI.ArcGIS.Geodatabase.IQueryFilter = New ESRI.ArcGIS.Geodatabase.QueryFilterClass() queryFilter.WhereClause = whereClause ' create the where clause statement if table.RowCount(queryFilter) = 0 then Return Nothing ' query the table passed into the function and use a cursor to hold the results Dim cursor As ESRI.ArcGIS.Geodatabase.ICursor = table.Search(queryFilter, False) Return cursor End Function
Ken, thank you, that did it!!
James, thanks for trying..haha! We call the field FileNumber and it's a String Field, because File Numbers can be alpha-numeric 😉