'select path from music1 where path='E:\软件作品\媒体播放\music\I'+''''+'m a pig.mp3'

解决方案 »

  1.   

    'select path from music1 where path='+''''+'E:\软件作品\媒体播放\music\I'+''''+'m a pig.mp3' 
      

  2.   

    这个sql语句是动态获得的,path是不确定的,我怎么样知道它获得的查询字段是正确的呢?
    比如这里的I'm a pig中出现了‘,产生了错误!
      

  3.   

    不考虑Delphi,单纯SQL串,是这样:select path from music1 where path='E:\软件作品\媒体播放\music\I''m a pig.mp3'
      

  4.   

    用AnsiQuotedStr函数,给你安全地加引号:
    function AnsiQuotedStr(const S: string; Quote: Char): string;
    S是原串,Quote用''''吧,返回的串是已经加了引号的,包括两头。DescriptionUse AnsiQuotedStr to convert a string (S) to a quoted string, using the provided Quote character.  A Quote character is inserted at the beginning and end of S, and each Quote character in the string is doubled.Note: This function supports multi-byte character sets (MBCS).
      

  5.   

    'select path from music1 where path= ''' + E + ''' + ''' + : + ''' +  \ + ''' + 软件作品 + ''' + \ + ''' + 媒体播放 + ''' + \ + ''' + music + \ + ''' + I + ''' + ''' + 'm a pig.mp3 + '''; 
      

  6.   

    query.close;
    query.sql.clear;
    query.sql.add('select path from music1 where path=:path');
    query.parambyname('path').asstring:='E:\软件作品\媒体播放\music\I'm a pig.mp3';
    query.open;
      

  7.   

    cqiu2000(算死草): 
    不行啊!还是出错啊!
      

  8.   

     agui(阿贵) :
    加的都是双引号,出错啊!
      

  9.   

    你可以先对取到的串取预处理一下,然后再做SELECT
      

  10.   

    yexiao(叶开):我说的是单引号啊,Delphi中一个单引号的表示要用两个双引号表示,而两边要分别加上一个单引号。不行了你就用#39或#$27代替。我的分啊~~~~~~~~~~~