This project has moved and is read-only. For the latest updates, please go here.

Escape String in DefinitionQuery

Topics: Data Access
Apr 5, 2007 at 3:25 PM
I've got SharpMap loading a layer from MssqlSpatial and everything looks great. Now I'm trying to use a DefinitionQuery on the MssqlSpatial Provider to show a predefined selection. It works fine when the query column is integer

mssqlSelection.DefinitionQuery = "TWP = 21";

However, when I try to use a text or varchar column for the query it is not working. I've tried multiple different ways and none seem to work.

mssqlSelection.DefinitionQuery = "STR = \"6-T21N-R2E\""; //returns a sql exception

mssqlSelection.DefinitionQuery = "STR = '6-T21N-R2E'"; //returns an incorrect syntax error

mssqlSelection.DefinitionQuery = "STR = \'6-T21N-R2E\'"; // sql exception

I must be missing something but I can't seem to figure out what's going on. I have changed the column type from varchar to text and it still has problems. Any help would be great. Thanks

Apr 5, 2007 at 8:12 PM
I updated my source to changeset 20766 and it seems to have solved the problem.

This works

mssqlSelection.DefinitionQuery = "STR = '6-T21N-R2E'";