The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

Filtering where the filter value contains " ' "?

Last post 08-17-2008, 12:51 AM by iVirtualDocket. 2 replies.
Sort Posts: Previous Next
  •  08-16-2008, 2:06 AM 10769

    Filtering where the filter value contains " ' "?

    Morning chaps, I'm currently migrating an old system into a new version of my application. The data I am trying to import is a list of addresses. Unfortunately many of those addresses contain a '.

    When I put those into the filter I.e. SiteName = 'Bob's Shop', it obviously falls over because it thinks the filter should have ended at 'Bob'. How can I make the filter include that character? I have tried doing a find and replace on the filter values and replacing ' with \', but that doesn't seem to work either.

    Unfortunately I have to keep that character, or I'd just strip it out.

     

     

    Code:
    1    string siteName = "Bob's Shop";
    2    
    3    TblSiteCollection siteList = new TblSiteCollection();
    4    siteList.Query.Where(siteList.Query.CompanyId.Equal(Settings.Default.CompanyId));
    5    siteList.Filter = TblSiteMetadata.ColumnNames.SiteName+ "='" + siteName + "'";
    
     

     

    Thanks in advance.

     


    Current ES Projects:
    iVirtualDocket - Remote engineer tracking and job assignments
    HIS - Home insurance scripting system
  •  08-16-2008, 4:24 AM 10770 in reply to 10769

    Re: Filtering where the filter value contains " ' "?

    Code:
    string siteName = "Bob''s Shop";

    That is two single quotes, not a double-quote. See the second Comment at the bottom of this page.

    http://msdn.microsoft.com/en-us/library/system.data.datacolumn.expression(VS.80).aspx

    Code:
    siteList.Filter = "[" + TblSiteMetadata.ColumnNames.SiteName + "] = '" + 
        siteName.Replace("'", "''") + "'";

    David Neal Parsons
    www.entityspaces.net
  •  08-17-2008, 12:51 AM 10774 in reply to 10770

    Re: Filtering where the filter value contains " ' "?

    Thanks David! Much appreciated.

    Current ES Projects:
    iVirtualDocket - Remote engineer tracking and job assignments
    HIS - Home insurance scripting system
View as RSS news feed in XML