Below you will find some simple code to execute a query from a shapefilefeaturesource. Please substitute with your data and try it out. An exception of "IErrorInfo.GetDescription failed with E_FAIL(0x80004005)" should appear on the ExecuteQuery line. If not, please inform me and I can perhaps supply my layer and we can verify what the exception is and why it is happening.............
Dim strSQL As String Dim strColumnName As String = "ZONE" Dim layerPath As String = "C:\Program Files\geotms\maps\lots.shp" Dim layerName As String Dim dt As New DataTable
If strColumnName <> Nothing Then Dim layerToAddSHP As New ShapeFileFeatureLayer(layerPath, ShapeFileReadWriteMode.ReadOnly)
It was suspicious that the magic is hidden in your shape file, so if possible can u send me the shape file “lots.shp”.
I use the following codes with a shape file attached in sample data, it works fine. Private Sub SqlQuery_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load winformsMap1.MapUnit = GeographyUnit.DecimalDegree winformsMap1.BackgroundOverlay.BackgroundBrush = New GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean)
Dim worldLayer As New ShapeFileFeatureLayer("..\..\SampleData\Data\USStates.shp") worldLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.State1 worldLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.OutlinePen.LineJoin = DrawingLineJoin.Round worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20
Dim staticOverlay As New LayerOverlay() staticOverlay.Layers.Add("WorldLayer", worldLayer) winformsMap1.Overlays.Add(staticOverlay)
winformsMap1.CurrentExtent = New RectangleShape(-178.0R, 71.5, -67.0R, 19.0R) winformsMap1.Refresh() End Sub
Private Sub btnExecute_Click(ByVal sender As Object, ByVal e As EventArgs) Dim worldLayer As ShapeFileFeatureLayer = DirectCast(winformsMap1.FindFeatureLayer("WorldLayer"), ShapeFileFeatureLayer)
Dim strColumnName As String = "PERIMETER" Dim layerName As String = System.IO.Path.GetFileNameWithoutExtension(worldLayer.ShapePathFileName)
Dim sqlStatement As String = "SELECT " & strColumnName & _ " FROM " & layerName & _ " GROUP BY " & strColumnName
worldLayer.RequireIndex = False worldLayer.Open() Dim dataTable As DataTable = worldLayer.QueryTools.ExecuteQuery(sqlStatement) worldLayer.Close()
Unfortunately, that may be the case. It is strange because it has been working fine all this time. My layer is too large to upload unfortunately so I will email support and request a forward to you with a link to this post.
The error at this point is my fault. I tried this code in a different part of my project and it worked correctly.
The problem I had been running into was a result of checking for DBNull against the column name including the brackets which you can not include once the data is packed into the DataTable.