Is there a way to standardise a where clause that may contain apostrophes (single quotes) in the string? I have a string 'RIVER'S EDGE CONDOMINIUM' that is causing the where clause in the query filter below to fail. How can I set up the where clause of the query filter to account for situations like the above while also accounting for regular string inputs? My code is shown below and it fails when the input string has an apostrophe in it. @CharlesMacleod @Wolf @UmaHarano
var qf = new SpatialQueryFilter();
qf.FilterGeometry = myShape;
qf.SpatialRelationship = SpatialRelationship.Intersects;
qf.WhereClause = $"{AllFieldnames.parcelNumFieldname} = '{intersctedParcelNum}'";
Solved! Go to Solution.
You have to replace the single quotation mark with two single quotation marks (the first one is used as an escape character).
var qf = new SpatialQueryFilter();
qf.FilterGeometry = myShape;
qf.SpatialRelationship = SpatialRelationship.Intersects;
qf.WhereClause = $"{AllFieldnames.parcelNumFieldname} = '{intersctedParcelNum.Replace("'","''")}'";
pre-process the string. i think "'" has to be escaped with another "'".
var str = "This has an embedded ' in it";
var strEscaped = str.Replace("'", "''");
qf.WhereClause = $"......'{strEscaped}'";
You have to replace the single quotation mark with two single quotation marks (the first one is used as an escape character).
var qf = new SpatialQueryFilter();
qf.FilterGeometry = myShape;
qf.SpatialRelationship = SpatialRelationship.Intersects;
qf.WhereClause = $"{AllFieldnames.parcelNumFieldname} = '{intersctedParcelNum.Replace("'","''")}'";