如query1.sql.add('select * from AA where bh=:abh');//abh为变量名
query1.parambyname('abh').asstring:='hello';//给abh赋值为hello
query1.open;但像query1.parambyname('paramname').value:=''若是输入的值是string类型用引好括起来,而integer类型不加括号吗?我试过了但总是出错(类型不匹配),why?

解决方案 »

  1.   

    以下这样不是更好吗
    query1.sql.add('select * from AA where bh='''+edit1.text +'''');//edit1.text := 'hello';
    //query1.sql.add('select * from AA where bh=''hello''');//这样也可以
    query1.sql.add('select * from AA where bh='999');//整型
    query1.open;
      

  2.   

    为什么不用query1.parambyname('paramname').asstring呢?如果是整型可以先转换一下,
    如:query1.parambyname('paramname').asstring:=inttostr(NN); //NN为整型变量
      

  3.   

    而integer类型不加括号
    但你数据库字段是整数型吗?
      

  4.   

    如果用query1.parambyname('paramname').value: 输入的值类型必须和数据库中该字段类型匹配,query1.parambyname('paramname').asXXX,系统已替你完成类型转换。只要XXX和所赋的值的类型一样就可以了。
      

  5.   

    如query1.sql.add('select * from AA where bh=:abh');//abh为变量名
    query1.parambyname('abh').asinteger:=3;
    如果你用的是INTEGER,那就asinteger,就可以了
      

  6.   

    要与字段的类型相匹配才行! 正確
    bh的類型是什麼你就填什麼
    .value=>.asXXX也很好啊ps:
    huojiehai(海天子) 
    以下这样不是更好吗
    query1.sql.add('select * from AA where bh='''+edit1.text +'''');//edit1.text := 'hello';
    //query1.sql.add('select * from AA where bh=''hello''');//这样也可以
    =====>>
    我還是建議採用樓主的寫法,動態偉參,好好想想,為什麼query1.sql.add('select * from AA where bh='999');//整型
    query1.open;
    ===>>不對吧,多了個單引號
    query1.sql.add('select * from AA where bh=999');//關鍵的一點就是bh的類型是什麼
      

  7.   

    query1.sql.add('select * from AA where bh=:abh');//abh为变量名
    query1.parambyname('abh').asstring:='hello';//给abh赋值为hello
    query1.open;改为:
    query1.sql.add('select * from AA where bh=:abh');//abh为变量名
    query1.parambyname('abh').value:='hello';//给abh赋值为hello
    query1.open;系统会自动完成类型转换。