CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2005
    Posts
    10

    [RESOLVED] Help with SQL in C#

    Hello everyone,

    I have a piece of code here that doesn't appear to work, and I think I know why, but I just can't get my head around a way to fix it. I'm am making a select statement from a database and doing a string comparison:

    <code>
    comm.CommandText = "SELECT Insurance_Company_Number, Insurance_Company_Name FROM TABLE_Insurance_Company WHERE Insurance_Company_Number = 'Hudson's Bay Co (Toronto)'";
    </code>

    Now, I'm certain the problem arises because of the apostrophe in Hudson's screwing around with the string, is there an escape sequence that I can use to use the ' as part of the string?

    The error that comes up is:
    Syntax Error (missing operator) in query expression 'Insurance_Company_Number = 'Hudson's Bay Co (Toronto)"

  2. #2
    Join Date
    Nov 2007
    Posts
    110

    Re: Help with SQL in C#

    The code tags actually use [] not <>.

    The escape in SQL is the apostrophe. So, in your string you would need to do two apostrophe's in order to escape it.

  3. #3
    Join Date
    Jul 2005
    Posts
    10

    Re: Help with SQL in C#

    Thanks for the help, seemed to get the job done.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured