Results 1 to 5 of 5

Thread: [2008] Single Collon Problem in QUERIES.

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2008
    Location
    Philippines
    Posts
    70

    [2008] Single Collon Problem in QUERIES.

    Hi can any one help me in solving the problem if I'm having an entry that has a single collon (')...

    when im retrieving it in a query and the data has a single collon (e.g. Jayson's Shift), it returns an error. Yes bcs the query has an odd number of collon, So if anyone experince this problem, pls share me the solution.
    Thanks

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2008] Single Collon Problem in QUERIES.

    That's a single quote, not a single collon.

    You should not use string concatenation to build SQL strings. If you always do it the proper way and use parameters this sort of thing is never an issue. Follow the Data Access link in my signature for some ADO.NET code examples involving parameters.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2008
    Location
    Philippines
    Posts
    70

    Re: [2008] Single Collon Problem in QUERIES.

    Why not??? is much easier that way... Im expecting that some one encountered this problem also... My idea is count the SINGLE QUOTE, and if it is odd, I will add another quote at the end of string. The problem is, I dont know how to check each character of the string.. if you have an idea on how to check each character, ill appreciate it. THANKS.

  4. #4
    Frenzied Member MaximilianMayrhofer's Avatar
    Join Date
    Aug 2007
    Location
    IM IN YR LOOP
    Posts
    2,001

    Re: [2008] Single Collon Problem in QUERIES.

    first of all that is a single quotation. and you need to escape it by putting two together.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2008] Single Collon Problem in QUERIES.

    Quote Originally Posted by bizzy_e23
    Why not??? is much easier that way... Im expecting that some one encountered this problem also... My idea is count the SINGLE QUOTE, and if it is odd, I will add another quote at the end of string. The problem is, I dont know how to check each character of the string.. if you have an idea on how to check each character, ill appreciate it. THANKS.
    No it isn't much easier that way. Yes many people have encountered this problem before. Each of them has been told the same thing: do it properly and use parameters.

    This is not the only reason to use parameters. They also remove the need to format dates. They make your code much more readable and less error prone. The most important reason to use parameters though is security. With string concatenation you can leave yourself open to SQL injection attacks, which is when the user adds some SQL code to the value they input and it gets executed on your database when it shouldn't. This can be a major security risk, allowing malicious users to do almost anything they want on your database. Get into good habits early. Do it the proper way now.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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