查询条件的值为数字类型(不是string),用ADOQuery怎么查询?(50分)

A

abv

Unregistered / Unconfirmed
GUEST, unregistred user!
表T2中的字段box类型为整数型。
我写的语句如下,报错类型不匹配。
ADOQuery5.close;
ADOQuery5.SQL.Clear;
ADOQuery5.SQL.Add('Select * from t2');
ADOQuery5.SQL.Add('where box ='''+ ListBox5.itemindex+1 +''');
ADOQuery5.Open;

请DX帮我改改。多谢~~
Access库
 
Inttostr(ListBox5.itemindex+1)
 
ADOQuery5.SQL.Add('where box ='''+ Inttostr(ListBox5.itemindex+1) +''');
 
ADOQuery5.SQL.Add('where box ='+ ListBox5.itemindex+1);
 
ADOQuery5.SQL.Add('where box ='+ inttostr(ListBox5.itemindex+1));
 
之前写错了,修正
ADOQuery5.SQL.Add('where box ='+ inttostr(ListBox5.itemindex+1));
 
这问题问的也太太简单了吧
 
就是一个类型转换:
ListBox5.itemindex本身是integer类型的,要做字符串连接你要将它转换为string才行

ADOQuery5.SQL.Add('where box ='+ inttostr(ListBox5.itemindex+1));
 
ADOQuery5.SQL.Add('where box ='+ inttostr(ListBox5.itemindex+1));
 
inttostr ;

编译的时候 自动检查 sql 能不能转换成string .

所以里面的参数 都要string 传进去.
 
box字段是整型的,如果inttostr()就会类型不匹配
 
ADOQuery5.SQL.Add('where box ='+ inttostr(ListBox5.itemindex+1));
 
ADOQuery5.SQL.Add('where box ='+ inttostr(ListBox5.itemindex+1));
用字符串傳進去沒問題的
 
参考这里吧:http://www.delphibbs.com/keylife/iblog_show.asp?xid=4212
 
多人接受
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
609
import
I
顶部