Sunday 22 July 2018

arcgis 10.0 - How do I query a string in Arcobjects that has a single quote in it?


I'm trying to query values using a cursor and loop for the process of removing diacritics. The problem I am running in to is that when I try to create a WhereClause like so...


qf.WhereClause = "\""+fieldname+"\" = "+"'"+address+"'";

I get a COMException about my query if the value of address has a single quote in it (i.e. Land o'Lakes). I have tried escaping the ' with address.Replace("'","\'") but the resulting string is unchanged. When I attempted to double-escape with address.Replace("'","\\'") , the string ends up with both backslashes.


What should I do?



Answer



I think it might matter what type of data source you are hitting but in general I suspect that doubling the single quote marks is the solution. So address.Replace( "'", "''"); should work.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...