# Odd error with layer.ExecuteQuery

**URL:** <https://community.thinkgeo.com/t/odd-error-with-layer-executequery/555>\
**Category:** WinForms\
**Created:** [July 21, 2009, 3:40pm UTC](https://community.thinkgeo.com/t/odd-error-with-layer-executequery/555 "2009-07-21T15:40:25Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nelson](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/n/dec6dc/32.png) [@Nelson](https://community.thinkgeo.com/u/Nelson)\
**Post date:** [July 21, 2009, 3:40pm UTC](https://community.thinkgeo.com/t/odd-error-with-layer-executequery/555/1 "2009-07-21T15:40:25Z")

</div>

Below&nbsp;you&nbsp;will&nbsp;find&nbsp;some&nbsp;simple&nbsp;code&nbsp;to&nbsp;execute&nbsp;a&nbsp;query&nbsp;from&nbsp;a&nbsp;shapefilefeaturesource.&nbsp;Please&nbsp;substitute&nbsp;with&nbsp;your&nbsp;data&nbsp;and&nbsp;try&nbsp;it&nbsp;out.&nbsp;An&nbsp;exception&nbsp;of&nbsp;"IErrorInfo.GetDescription&nbsp;failed&nbsp;with&nbsp;E\_FAIL(0x80004005)"&nbsp;should&nbsp;appear&nbsp;on&nbsp;the&nbsp;ExecuteQuery&nbsp;line.&nbsp;If&nbsp;not,&nbsp;please&nbsp;inform&nbsp;me&nbsp;and&nbsp;I&nbsp;can&nbsp;perhaps&nbsp;supply&nbsp;my&nbsp;layer&nbsp;and&nbsp;we&nbsp;can&nbsp;verify&nbsp;what&nbsp;the&nbsp;exception&nbsp;is&nbsp;and&nbsp;why&nbsp;it&nbsp;is&nbsp;happening.............

&nbsp;

&nbsp;

`        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)            layerName = System.IO.Path.GetFileNameWithoutExtension(layerPath)            strSQL = "SELECT " & strColumnName & _                    " FROM " & layerName & _                    " GROUP BY " & strColumnName            layerToAddSHP.RequireIndex = False            Try                layerToAddSHP.Open()                dt = layerToAddSHP.QueryTools.ExecuteQuery(strSQL)            Finally                If layerToAddSHP.IsOpen Then layerToAddSHP.Close()            End Try        End If    End Sub`

---

<div class="post-metadata">

**Author:** ![ThinkGeo](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/thinkgeo/32/25029_2.png) [@ThinkGeo](https://community.thinkgeo.com/u/ThinkGeo)\
**Post date:** [July 21, 2009, 8:59pm UTC](https://community.thinkgeo.com/t/odd-error-with-layer-executequery/555/2 "2009-07-21T20:59:36Z")

</div>

Nelson,

It&nbsp;was&nbsp;suspicious&nbsp;that&nbsp;the&nbsp;magic&nbsp;is&nbsp;hidden&nbsp;in&nbsp;your&nbsp;shape&nbsp;file,&nbsp;so&nbsp;if&nbsp;possible&nbsp;can&nbsp;u&nbsp;send&nbsp;me&nbsp;the&nbsp;shape&nbsp;file&nbsp;“lots.shp”.  
&nbsp;  
I&nbsp;use&nbsp;the&nbsp;following&nbsp;codes&nbsp;with&nbsp;a&nbsp;shape&nbsp;file&nbsp;attached&nbsp;in&nbsp;sample&nbsp;data,&nbsp;it&nbsp;works&nbsp;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()            dgridResult.DataSource = dataTable        End Sub`

Let&nbsp;me&nbsp;know&nbsp;if&nbsp;still&nbsp;any&nbsp;more&nbsp;questions.

Thanks.  
&nbsp;  
Yale

---

<div class="post-metadata">

**Author:** ![Nelson](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/n/dec6dc/32.png) [@Nelson](https://community.thinkgeo.com/u/Nelson)\
**Post date:** [July 22, 2009, 6:56am UTC](https://community.thinkgeo.com/t/odd-error-with-layer-executequery/555/3 "2009-07-22T06:56:52Z")

</div>

Unfortunately,&nbsp;that&nbsp;may&nbsp;be&nbsp;the&nbsp;case.&nbsp;It&nbsp;is&nbsp;strange&nbsp;because&nbsp;it&nbsp;has&nbsp;been&nbsp;working&nbsp;fine&nbsp;all&nbsp;this&nbsp;time.&nbsp;My&nbsp;layer&nbsp;is&nbsp;too&nbsp;large&nbsp;to&nbsp;upload&nbsp;unfortunately&nbsp;so&nbsp;I&nbsp;will&nbsp;email&nbsp;support&nbsp;and&nbsp;request&nbsp;a&nbsp;forward&nbsp;to&nbsp;you&nbsp;with&nbsp;a&nbsp;link&nbsp;to&nbsp;this&nbsp;post.

---

<div class="post-metadata">

**Author:** ![ThinkGeo](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/thinkgeo/32/25029_2.png) [@ThinkGeo](https://community.thinkgeo.com/u/ThinkGeo)\
**Post date:** [July 22, 2009, 9:55pm UTC](https://community.thinkgeo.com/t/odd-error-with-layer-executequery/555/4 "2009-07-22T21:55:53Z")

</div>

Nelson,

Thanks&nbsp;for&nbsp;your&nbsp;post!  
&nbsp;  
I&nbsp;think&nbsp;the&nbsp;reason&nbsp;is&nbsp;that&nbsp;ZONE&nbsp;is&nbsp;the&nbsp;reserved&nbsp;keywords&nbsp;that&nbsp;used&nbsp;by&nbsp;SQL&nbsp;statement.&nbsp;You&nbsp;can&nbsp;find&nbsp;it&nbsp;below:  
[developer.mimer.com/validato...-words.tml](http://developer.mimer.com/validator/sql-reserved-words.tml)  
&nbsp;  
One&nbsp;way&nbsp;to&nbsp;correct&nbsp;this&nbsp;to&nbsp;add&nbsp;the&nbsp;bracket&nbsp;around&nbsp;this&nbsp;word  
Select&nbsp;[ZONE]&nbsp;From&nbsp;LOTS  
&nbsp;  
So,&nbsp;just&nbsp;change&nbsp;the&nbsp;following&nbsp;statement:  
`Dim strColumnName As String = "[ZONE]"`

Any&nbsp;more&nbsp;questions&nbsp;just&nbsp;let&nbsp;me&nbsp;know.

Thanks.  
&nbsp;  
Yale

---

<div class="post-metadata">

**Author:** ![Nelson](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/n/dec6dc/32.png) [@Nelson](https://community.thinkgeo.com/u/Nelson)\
**Post date:** [July 23, 2009, 6:40am UTC](https://community.thinkgeo.com/t/odd-error-with-layer-executequery/555/5 "2009-07-23T06:40:45Z")

</div>

Yale,&nbsp;when&nbsp;placing&nbsp;brackets&nbsp;around&nbsp;my&nbsp;columnName,&nbsp;I&nbsp;get&nbsp;the&nbsp;following&nbsp;error:&nbsp;  
&nbsp;&nbsp;  
&nbsp;Column&nbsp;‘[ZONE]’&nbsp;does&nbsp;not&nbsp;belong&nbsp;to&nbsp;table.

---

<div class="post-metadata">

**Author:** ![ThinkGeo](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/thinkgeo/32/25029_2.png) [@ThinkGeo](https://community.thinkgeo.com/u/ThinkGeo)\
**Post date:** [July 23, 2009, 7:44pm UTC](https://community.thinkgeo.com/t/odd-error-with-layer-executequery/555/6 "2009-07-23T19:44:28Z")

</div>

Nelson,

That&nbsp;is&nbsp;strange!  
&nbsp;  
Can&nbsp;you&nbsp;try&nbsp;to&nbsp;do&nbsp;the&nbsp;sql&nbsp;statement&nbsp;test&nbsp;on&nbsp;MapSuiteExplorer&nbsp;as&nbsp;following&nbsp;screenshot&nbsp;shows

 ![](https://community.thinkgeo.com/uploads/default/original/2X/0/0534a6dd53026c6d0a77b81a7e7159384c5a68cb.png)&nbsp;  
&nbsp;  
Let&nbsp;me&nbsp;know&nbsp;if&nbsp;you&nbsp;have&nbsp;any&nbsp;more&nbsp;questions.  
&nbsp;  
Thanks.  
&nbsp;  
Yale  

&nbsp;

---

<div class="post-metadata">

**Author:** ![Nelson](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/n/dec6dc/32.png) [@Nelson](https://community.thinkgeo.com/u/Nelson)\
**Post date:** [July 24, 2009, 8:07am UTC](https://community.thinkgeo.com/t/odd-error-with-layer-executequery/555/7 "2009-07-24T08:07:41Z")

</div>

The&nbsp;error&nbsp;at&nbsp;this&nbsp;point&nbsp;is&nbsp;my&nbsp;fault.&nbsp;I&nbsp;tried&nbsp;this&nbsp;code&nbsp;in&nbsp;a&nbsp;different&nbsp;part&nbsp;of&nbsp;my&nbsp;project&nbsp;and&nbsp;it&nbsp;worked&nbsp;correctly.

The&nbsp;problem&nbsp;I&nbsp;had&nbsp;been&nbsp;running&nbsp;into&nbsp;was&nbsp;a&nbsp;result&nbsp;of&nbsp;checking&nbsp;for&nbsp;DBNull&nbsp;against&nbsp;the&nbsp;column&nbsp;name&nbsp;including&nbsp;the&nbsp;brackets&nbsp;which&nbsp;you&nbsp;can&nbsp;not&nbsp;include&nbsp;once&nbsp;the&nbsp;data&nbsp;is&nbsp;packed&nbsp;into&nbsp;the&nbsp;DataTable.

Thank&nbsp;you,&nbsp;Yale.

---

<div class="post-metadata">

**Author:** ![ThinkGeo](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/thinkgeo/32/25029_2.png) [@ThinkGeo](https://community.thinkgeo.com/u/ThinkGeo)\
**Post date:** [July 26, 2009, 7:37pm UTC](https://community.thinkgeo.com/t/odd-error-with-layer-executequery/555/8 "2009-07-26T19:37:01Z")

</div>

Nelson,&nbsp;You&nbsp;are&nbsp;welcome!&nbsp;  
&nbsp;&nbsp;  
&nbsp;Any&nbsp;more&nbsp;questions&nbsp;just&nbsp;let&nbsp;me&nbsp;know!&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Yale
