<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Simple SQL Query, .net in .NET Maps SDK Questions</title>
    <link>https://community.esri.com/t5/net-maps-sdk-questions/simple-sql-query-net/m-p/1508911#M12891</link>
    <description>&lt;P&gt;This is probably going to be a simple answer, but im having some trouble formatting an SQL query in C#.&lt;/P&gt;&lt;P&gt;I need to query a featuretable and pick out a feature that has a matching "fips".&amp;nbsp;&lt;/P&gt;&lt;P&gt;the feature name is a string, example shows a number but they can be strings.&lt;/P&gt;&lt;P&gt;When I use the following code, I keep getting a return (featureresult2) of ALL the features in the table. I have tried a few different ways of phrasing the query, but it seems I am missing something.&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000FF"&gt;name = S.UniqueID;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000FF"&gt;//Lets look up the geometry&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;string s = "fips";&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;string columnName = s;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;string searchString = name;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;// string sqlQuery = $"{columnName} = {searchString}";//Returning all&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;string sqlQuery = "fips = '270530265081'"; //Testing simple, still returning all&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;QueryParameters queryParams = new QueryParameters //Selects the fips&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;{ &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;WhereClause = sqlQuery&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;};&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;FeatureQueryResult featureResult2;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;featureResult2 = (BlockGroupGeoPackage.GeoPackageFeatureTables[0].QueryFeaturesAsync(queryParams).GetAwaiter().GetResult());&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 23 Jul 2024 21:20:50 GMT</pubDate>
    <dc:creator>SP2501</dc:creator>
    <dc:date>2024-07-23T21:20:50Z</dc:date>
    <item>
      <title>Simple SQL Query, .net</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/simple-sql-query-net/m-p/1508911#M12891</link>
      <description>&lt;P&gt;This is probably going to be a simple answer, but im having some trouble formatting an SQL query in C#.&lt;/P&gt;&lt;P&gt;I need to query a featuretable and pick out a feature that has a matching "fips".&amp;nbsp;&lt;/P&gt;&lt;P&gt;the feature name is a string, example shows a number but they can be strings.&lt;/P&gt;&lt;P&gt;When I use the following code, I keep getting a return (featureresult2) of ALL the features in the table. I have tried a few different ways of phrasing the query, but it seems I am missing something.&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000FF"&gt;name = S.UniqueID;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000FF"&gt;//Lets look up the geometry&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;string s = "fips";&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;string columnName = s;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;string searchString = name;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;// string sqlQuery = $"{columnName} = {searchString}";//Returning all&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;string sqlQuery = "fips = '270530265081'"; //Testing simple, still returning all&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;QueryParameters queryParams = new QueryParameters //Selects the fips&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;{ &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;WhereClause = sqlQuery&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;};&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;FeatureQueryResult featureResult2;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;featureResult2 = (BlockGroupGeoPackage.GeoPackageFeatureTables[0].QueryFeaturesAsync(queryParams).GetAwaiter().GetResult());&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jul 2024 21:20:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/simple-sql-query-net/m-p/1508911#M12891</guid>
      <dc:creator>SP2501</dc:creator>
      <dc:date>2024-07-23T21:20:50Z</dc:date>
    </item>
    <item>
      <title>Re: Simple SQL Query, .net</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/simple-sql-query-net/m-p/1509002#M12893</link>
      <description>&lt;P&gt;I don't see anything wrong with how you formed the query. String equality looks correct provided the field exists with the correct name and type. If you want query to return just one, you can set MaxFeatures = 1; but if you say this value is unique then you should expect a single feature returned without MaxFeatures.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;var attributeValue = "270530265081";

var table = BlockGroupGeoPackage.GeoPackageFeatureTables[0];
var tableField = table.GetField("fips");


var query = new QueryParameters()
{
  WhereClause = $"{tableField.Name} = '{attributeValue}'",
  MaxFeatures = 1
};


&lt;/LI-CODE&gt;&lt;P&gt;I would await the result of query though and may be inspect the features that come back. Output window should have the attribute value for each feature.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;var features = await table.QueryFeaturesAsync(query);

foreach(var feature in features)
{
  // Consider printing other attributes to identify the feature (i.e. OBJECTID)
  System.Diagnostics.Debug.WriteLine($"{tableField.Name}: feature.Attribute[tableField.Name]")
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jul 2024 01:26:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/simple-sql-query-net/m-p/1509002#M12893</guid>
      <dc:creator>JenniferNery</dc:creator>
      <dc:date>2024-07-24T01:26:52Z</dc:date>
    </item>
    <item>
      <title>Re: Simple SQL Query, .net</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/simple-sql-query-net/m-p/1509005#M12894</link>
      <description>&lt;P&gt;On an un-related note, try and avoid blocking code like '&lt;SPAN&gt;GetAwaiter().GetResult());' but instead use async/await for all async methods.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;There's a very large chance that you could deadlock the application without it.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jul 2024 01:34:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/simple-sql-query-net/m-p/1509005#M12894</guid>
      <dc:creator>dotMorten_esri</dc:creator>
      <dc:date>2024-07-24T01:34:15Z</dc:date>
    </item>
    <item>
      <title>Re: Simple SQL Query, .net</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/simple-sql-query-net/m-p/1509254#M12895</link>
      <description>&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;Looks like you were correct, and the query was good. The inspect loop you provided would only run once even when I removed the max results of the query.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Turns out this was in issue with Visual Studios watch command. Watching the NumberOfFeatures of the query results(features), seems to be a count of the original table being queried.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the help!&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jul 2024 13:55:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/simple-sql-query-net/m-p/1509254#M12895</guid>
      <dc:creator>SP2501</dc:creator>
      <dc:date>2024-07-24T13:55:43Z</dc:date>
    </item>
    <item>
      <title>Re: Simple SQL Query, .net</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/simple-sql-query-net/m-p/1509280#M12896</link>
      <description>&lt;P&gt;No problem.&lt;/P&gt;&lt;P&gt;The &lt;A href="https://developers.arcgis.com/net/api-reference/api/netfx/Esri.ArcGISRuntime/Esri.ArcGISRuntime.Data.FeatureTable.NumberOfFeatures.html" target="_blank" rel="noopener"&gt;NumberOfFeatures&lt;/A&gt; would be a cumulative value of the features retrieved in the table so far. So if you have this table rendered as a layer on a map, a query with view extent would have already run to fetch features. Or if you had previous queries made with different fips value.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;There is a &lt;A href="https://developers.arcgis.com/net/api-reference/api/netfx/Esri.ArcGISRuntime/Esri.ArcGISRuntime.Data.FeatureTable.QueryFeatureCountAsync.html" target="_blank" rel="noopener"&gt;QueryFeatureCountAsync&lt;/A&gt; method if you only want the count for features from a specific query. But if you will be working on the features returned from QueryFeaturesAsync then you can use features.Count() instead where features is the return value of the awaited query task.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jul 2024 14:32:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/simple-sql-query-net/m-p/1509280#M12896</guid>
      <dc:creator>JenniferNery</dc:creator>
      <dc:date>2024-07-24T14:32:43Z</dc:date>
    </item>
  </channel>
</rss>

