Select to view content in your preferred language

Query Table Error

453
2
09-29-2022 12:05 PM
tzz_12
by
New Contributor III

I am wondering how I can fix this WhereClause? Everything seems to work, except for the query. Thanks for your help!

QueuedTask.Run(() =>
{
     string mKey = "462409";

      var ckeys = new string[3] { "19605542","19605543","19605707" };

       using (Geodatabase geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new  Uri(inPath))))

       using (var HzTable = geodatabase.OpenDataset<Table>("TableName"))
        {
              foreach (var Ckey in ckeyList)
              {
                  QueryFilter qf = new QueryFilter()
                 {
                         WhereClause = $@"ckey = {Ckey}",

                  };

                  using (var rowCursor = HzTable.Search(qf))  //error here
                 {
                     while (rowCursor.MoveNext())
                     {
                           using (Row row = rowCursor.Current)
                           {

                               Calculations performed here...etc.

 

 

 

0 Kudos
2 Replies
KenBuja
MVP Esteemed Contributor

If you're filtering on a string field, you need to enclose the variable in quotes

WhereClause = $@"ckey = '{Ckey}'",
Wolf
by Esri Regular Contributor
Esri Regular Contributor

Depending on the datatype of ckey field you might have to change your syntax so that:

 WhereClause = $@"ckey = {Ckey}",

could turn into this:

 WhereClause = $@"ckey = '{Ckey}'",

 Needless to say the field 'ckey' must exists in the table "TableName"