'select * from tb_rentprice where a <='+#39+j+#39+' and b>'+#39+j+#39+' and c='+#39+sjlx+#39+''数据库为access,其中price_down和price_up为数字类型的,c为字符类型的 出现的错误是"标准表达式中数据类型不匹配"
你的数据库里a\b\c是什么类型?select * from tb_rentprice where a <='j' and b>'j' and c='sjlx'先直接拿到查询器中调试过再说
'select * from tb_rentprice where a <='+#39+j+#39+' and b>'+#39+j+#39+' and c='+#39+sjlx+#39+''数据库为access,其中a和b为数字类型的,c为字符类型的,j和sjlx是string类型的 出现的错误是"标准表达式中数据类型不匹配"
这个语句在sql的数据库是可以用的,但是现在把数据库换成了access的数据库,每次到这里就会出错
select * from tb_rentprice where (a <='+#39+j+#39+') and (b>'+#39+j+#39+') and (c='+#39+sjlx+#39+')
? 现在不是转化的问题啊,是那个sql语句无法运行,谁能给我指出问题出在哪里,怎么样解决啊? var i:integer; j:string; begin j:='21'; ADOQuery1.Close; ADOQuery1.SQL.Clear; ADOQuery1.SQL.Add('select * from tb_rentprice where a <='+#39+j+#39+' and b>'+#39+j+#39+''); ADOQuery1.Open; end; 数据库为access,其中a和b为数字类型的,j是string类型的 出现的错误是"标准表达式中数据类型不匹配"就是写一个比较简单的程序,如上,还是会出那样的错误啊!
如果表里是数值类型那就不能加上单引号 'select * from tb_rentprice where a <=' + j + ' and b>' + j + ' and c=' + #39 + sjlx + #39;
from tb_rentprice
where a <='j' and b>'j' and c='sjlx'先直接拿到查询器中调试过再说
出现的错误是"标准表达式中数据类型不匹配"
from tb_rentprice
where (a <='+#39+j+#39+') and (b>'+#39+j+#39+') and (c='+#39+sjlx+#39+')
问题是不是在于j是string类型,而数据库中的a和b书数字类型啊?他们之间怎么转化啊?
可以在delphi里将strtoint成数字类型,这样我的sql怎么写啊??
现在不是转化的问题啊,是那个sql语句无法运行,谁能给我指出问题出在哪里,怎么样解决啊?
var
i:integer;
j:string;
begin
j:='21';
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('select * from tb_rentprice where a <='+#39+j+#39+' and b>'+#39+j+#39+'');
ADOQuery1.Open;
end;
数据库为access,其中a和b为数字类型的,j是string类型的
出现的错误是"标准表达式中数据类型不匹配"就是写一个比较简单的程序,如上,还是会出那样的错误啊!
'select * from tb_rentprice where a <=' + j + ' and b>' + j + ' and c=' + #39 + sjlx + #39;
//1、SQL.Clear; SQL.Add; -> SQL.Text := ...;
//2、采用Format()组合字符串
//3、QuotedStr()给字符串加单引号//其中字符串有单引号也被处理var
j: string;
sjlx: string;
begin
j := '21';
sjlx := '21';
ADOQuery1.Close;
ADOQuery1.SQL.Text := Format(
'select *'#13#10 +
'from tb_rentprice'#13#10 +
'where a<=%s and b>%s and c=%s', [j, j, QuotedStr(sjlx)]);
ADOQuery1.Open;
end;