如题

解决方案 »

  1.   

    SQL语句:select  * from  userinfo  where  name = 'aaa';delphi中:  'select * from userinfo  where  name = ''aaa''';
      

  2.   

    1。delphi中 两个单引号就是了
     如 : '''' 就是单引号2。也可用QuotedStr()函数给字符窜加引号
    如  str := 'select * from userinfo  where  name = ' + QuotedStr('aaa');
      

  3.   

    with ADOQ do
    begin
      Close;
      SQL.Clear;
      SQL.Add('SELECT Name FROM Information WHERE FirstName = ''' + edt_fn.Text + ''' AND Favorite = ''Delphi'' AND MAN = ' + edt_man.Text);
      Open;
    end;字段 FirstName char(12); Favorite char(15); MAN bit;
      

  4.   

    with ADOQ do
    begin
      Close;
      SQL.Clear;
      SQL.Add('SELECT Name FROM Information WHERE FirstName = '+''' + edt_fn.Text + '''+'AND Favorite ='+'''+Delphi+''' AND MAN = ' + edt_man.Text);
      Open;
    end;
      

  5.   

    SQL语句:select  * from  userinfo  where  name = 'aaa';delphi中:  'select * from userinfo  where  name = ''aaa''';
      

  6.   


    情况1 
    在delphi里字符串类型两边加''坯布'' 这样拼出的是'坯布'表示一个字符串
    而在query里,因为两边没有'...' 正常写'坯布'情况2
    在delphi里变量这样写'''+edit1.Text+''',就是把edit1.Text的内容加上string类型的标示符。 而在delphi中'''才拼出一个'是因为两边有'........'影响。
    如 sql1:='select * fromchuku_table where'+fieldbyname('ziduanmc1').asstring+''+fieldbyname('tiaojian1').asstring+''+fieldbyname('zhi').asstring+''; 这是符串型相加合,所以变量不用考虑'的问题,就直接拼情况3下面是变量加两个%后组成的字符      ''%'能拼出'%
    ('select  * from qq_table where truename like ''%'+edit1.text+'%''') ;
      

  7.   

    如下所例子:
                ' from PspStockMoveCong a join PspStockMove b on a.Key_id=b.Key_id'+
                ' where b.Shop_id='''+ShopID+''' and b.St_id='''+StID+''''+
                ' and ((a.Goods_id like '''+'%'+trim(Edt_Find1.Text)+'%'+''') or (a.Goods_barcode like '''+'%'+trim(Edt_Find1.Text)+'%'+'''))'+
                ' and b.operate_date>='''+FormatDateTime('yyyy-mm-dd hh:mm:ss ',DTP_BeginDiaoBo.Datetime)+''''+
                ' and b.operate_date<='''+FormatDateTime('yyyy-mm-dd hh:mm:ss',DTP_EndDiaoBo.Datetime)+''''+
                ' Group by a.Goods_id,a.Goods_barcode,a.Goods_name) c'+
                ' left join GoodsInfo d on c.Goods_id=d.Goods_id'如果对这个引号不好把握:可用Format()函数;
    如:
        SqlStr:=SqlStr+Format(' select * from [%S].[%S].[%S].[%S] b',[Local_Server,Local_DB,Local_User,TableName]);
      

  8.   

    用QuotedStr吧,这样最易读,而且以后移植也方便
      

  9.   

    可用的方式有三:
    1.sqlstr:='select * from tablename where columnName='+quotedstr('valuesString');
    2.sqlstr:='select * from tablename where columnName='+#39+'valuesString'+#39;
    3.sqlstr:=format('select * from tablename where columnName=''%s''',['valuesString']);
      

  10.   

    delphi中 两个单引号就是了
     如 : '''' 就是单引号
    也可用#39来替代.
      

  11.   

    在string中''代表单个单引号...
    ''字串''代表一组单引号
      

  12.   

    用QuotedStr();
    eg:ADODataSet.Commandtext := 'select * from table where field=' + QuotedStr('value');
      

  13.   

    sq:= 'select * from userinfo  where  name = %s and address=%s';
    sq:=Format(sq,['张三',北京]);
      

  14.   

    sq:= 'select * from userinfo  where  name = %s and address=%s';
    sq:=Format(sq,[QuotedStr('张三'),QuotedStr('北京')]);
      

  15.   


    + #39 + tmp_str + #39
      

  16.   

    delphi中 两个单引号就是了
     如 : '''' 就是单引号
    也可用#39来替代.
      

  17.   

    BDE连接的话。可以用:"字符"          来代替 '字符'
      

  18.   

    人好多啊
    ''代表一个单引号
    ''''也代表一个单引号
    quotedstr()
      

  19.   

    QuotedStr()
    ''''
    .....
      

  20.   

    一對''編繹後就是一個'.這是delphi編繹器這樣子做的。
    如:
    sql:='select a,b,c from table where a='''+edti1.text+''''
    編繹後:
    select a,b,c from table where a='abc'  //abc是edit1.text的值。
      

  21.   

    如果不会用引号,可以用参数来解决
    比如   ADOQuery1.SQL.Clear;
      ADOQuery1.SQL.Add('select * from 网络用户表 where 姓名=:fname');
      ADOQuery1.Parameters.ParamValues['fname']:='张三';
      ADOQuery1.Open;
      

  22.   

    try
      query1.close;
      query1.sql.clear;
      query1.sql.add(' select * from 学生信息表');
      query1.SQL.add(' where LastName='''+edit1.text+'''');
      query1.Prepare;
      query1.open;
    except
      showmessage('...');
    end;
      

  23.   

    在字符串中一个单引号用两个来表示;'123' 表示 123
    如果是 12'3 要写成字符串那么应该是 '12''3' 
    用 QuotedStr 容易读,但是,也存在问题,比如12'3 这样的字符串要传递给 QuotedStr 还得写成 QuotedStr('12''3') ; 你只要搞懂单引号的意思就行了,不一定要用QuotedStr
      

  24.   

    如果是selct * from table where name = 'zhangsheng'你可以写成:sqlstr ;= 'select * from table where name = ' + #39  + 'zhangsheng' + #39;
      

  25.   

    id := '1012';
    s := 'select * from dept where deptcode like ''' + id + '%''';结果是:select * from dept where deptcode like '1012%'
      

  26.   

    SQL语句:select  * from  userinfo  where  name = 'aaa';delphi中:  'select * from userinfo  where  name = ''aaa''';就是这样
      

  27.   

    我曾经也是遇到过这样的问题:
    我总结了一下一共有三种方法:
    1.使用''来用
    例:'select * from tablename where id='''+id+'''';
    2.使用#39
    例:'select * from tablename where id='+#39+id+#39;
    3.使用QuotedStr:
    函数原形:function QuotedStr(const S:string):string;
    例:'select * from tablename where id='+QuotedStr(id);
      

  28.   

    aiirii(ari-爱的眼睛) 你的信誉分好高呀!
    怎么加的?
    能不能告诉我怎么加呀?
    谢谢!!!
      

  29.   

    Delphi中两个单引号表示SQL中一个单引号
      

  30.   

    str := 'select * from userinfo  where  name = ' + QuotedStr('aaa');
      

  31.   

    1 QuotedStr
    2 '''
    3 #39
    说来说去,就这三种
      

  32.   

    sql :where name='aa' 
    delphi:'where name=''aa'''
      

  33.   

    QuotedStr+ #39
    我一直用这两个的。
      

  34.   

    delphi中:
    adoquery.close;
    adoquery.sql.clear;
    adoquery.sql.add('select * from table1 where id='''+edit.text+'''');
    adoquery.open;SQL中:
     select * from table where id in('0001','0006')
      

  35.   

    1、#39+内容+#39        ='内容'
    2、''内容''            ='内容'
    3、QuotedStr(内容)函数 ='内容'
      

  36.   

    这一贴都能到“论坛热贴”中去?
    CSDN真是堕落了……
      

  37.   

    用QuotedStr函数,就可以起到打引号的作用
      

  38.   

    1。delphi中 两个单引号就是了
     如 : '''' 就是单引号2。也可用QuotedStr()函数给字符窜加引号
    如  str := 'select * from userinfo  where  name = ' + QuotedStr('aaa');
    这个答案最好
      

  39.   

    QuotedStr()
    QuotedStr()
    QuotedStr()
      

  40.   

    formate()
    QuotedStr()
    ''' '''
    #39++#39
      

  41.   

    搂主:
    用 QuotedStr 吧````````````
      

  42.   

    adoquery1.SQL.Clear;
        adoquery1.SQL.Add('select * from 表1 where 客户 like '''+'%'+edit2.text+'%''');
        adoquery1.Open;
        dbref();
      

  43.   


    建議建立個數據庫, 將所有能夠在delphi里怎么打sql的单引号的答案保存起來,
    方便子孫萬代來查詢啊!!!
    國為樓上的精英們回答太完美了!
      

  44.   

    delphi中:  'select * from userinfo  where  name = ''aaa''';
    这个可以写成
    'select * from userinfo  where  name = '''aaa''''吗????
      

  45.   

    'select * from userinfo  where  name = '+''''+aaa+'''';
      

  46.   

    我kao,一个多月了,这个帖子还浮在水面上。比水贴人气还旺啊。
    搂主,解决了就揭贴啊,未必还没想要的答案?