Incompatible types:'String' and 'Integer' 急救,谢谢

goodle 2003-09-13 10:32:03
原代码如下:
var
str:String;
DeviceID:integer;
begin
if EditNum2.Text<>'' then
begin
str:=EditNum2.Text;
DeviceID:=StrToInt(str);
QueryDevice.Close;
QueryDevice.SQL.Clear;
QueryDevice.SQL.Add('select * from device ');
QueryDevice.SQL.Add('where 编号='''+DeviceID+'''');
QueryDevice.Open;
错误提示如标题,本人想从device表中提取编号为文本框所输入的值,编号为整型,当我把QueryDevice.SQL.Add('where 编号='''+DeviceID+'''');改为QueryDevice.SQL.Add('where 编号='''+EditNum2.Text+'''');的时候又查询不到记录,请问何解???

...全文
551 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
goodle 2003-09-15
  • 打赏
  • 举报
回复
好,谢谢各位
eaglezhao 2003-09-14
  • 打赏
  • 举报
回复
你的数据库中编号是字符还是数值性?SQL语句有区别的。
Eastunfail 2003-09-14
  • 打赏
  • 举报
回复
QueryDevice.SQL.Add('select * from device where where 编号=%d', [EditNum2.Text]);

你两个where当然有问题。另外。%d表示的是整数类型,而不是字符串类型。改为
QueryDevice.SQL.Add('select * from device where 编号=%s', [EditNum2.Text]);
goodle 2003-09-14
  • 打赏
  • 举报
回复
编号是字符还是数值性?SQL语句有区别的

请问各位,具体区别在那里,谢谢
goodle 2003-09-14
  • 打赏
  • 举报
回复
编号在数据库中为整型
goodle 2003-09-13
  • 打赏
  • 举报
回复
lxpbuaa(桂枝香在故国晚秋)

唉,我也不知道,同样的错误
lxpbuaa 2003-09-13
  • 打赏
  • 举报
回复
如果你的数据库中“编号”的确是整数类型的话,那么:
QueryDevice.SQL.Add('select * from device where 编号 =' + Trim(EditNum2.Text));
是不应该有错的。

—————————————————————————————————
宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。
—————————————————————————————————
goodle 2003-09-13
  • 打赏
  • 举报
回复
唉,我都服了,还是要谢谢各位的帮忙

to zousoft(好心肠的肉干)

编译错误:
Too many actual parameters
Ordinal type required
goodle 2003-09-13
  • 打赏
  • 举报
回复
to lxpbuaa(桂枝香在故国晚秋)

错误提示:general sql error
参数不足,期待值是1
zousoft 2003-09-13
  • 打赏
  • 举报
回复
QueryDevice.SQL.Add('select * from device where where 编号=%d', [EditNum2.Text]);
lxpbuaa 2003-09-13
  • 打赏
  • 举报
回复
QueryDevice.SQL.Add('where 编号=' + EditNum2.Text);

—————————————————————————————————
宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。
—————————————————————————————————
goodle 2003-09-13
  • 打赏
  • 举报
回复
to Eastunfail(浴血雏龙)==(恶鱼杀手) 麻烦你拉


begin
if EditNum2.Text<>'' then
begin
QueryDevice.Close;
QueryDevice.SQL.Clear;
QueryDevice.SQL.Add('select * from device ');
QueryDevice.SQL.Add('where 编号="'+EditNum2.Text+'"');

用这个也是同样的错误
QueryDevice.Open;
goodle 2003-09-13
  • 打赏
  • 举报
回复
先谢谢各位

to Eastunfail(浴血雏龙)==(恶鱼杀手)


QueryDevice.SQL.Add(Format('where 编号="%d"',[DeviceID]));
错误提示:general sql error
参数不足,期待值是2

goodle 2003-09-13
  • 打赏
  • 举报
回复
to Eastunfail(浴血雏龙)==(恶鱼杀手)

那样好象查询不到值
Eastunfail 2003-09-13
  • 打赏
  • 举报
回复
为了避免多次转换,应该这样:
var
DeviceID:integer;
begin
if EditNum2.Text<>'' then
begin
QueryDevice.Close;
QueryDevice.SQL.Clear;
QueryDevice.SQL.Add('select * from device ');
QueryDevice.SQL.Add('where 编号="'+EditNum2.Text+'"');
QueryDevice.Open;
zhxfzhxf1 2003-09-13
  • 打赏
  • 举报
回复

QueryDevice.SQL.Add('where 编号='''+DeviceID+'''');

->


QueryDevice.SQL.Add('where 编号='''+IntToStr(DeviceID)+'''');
Eastunfail 2003-09-13
  • 打赏
  • 举报
回复
你可以运行一下这个代码,估计你就知道是什么意思了:


ShowMessage(Format('当前窗口(%s)的实例指针是%p,坐标(%d,%d),大小:%d*%d',[Self.Caption,Pointer(Self),Self.Left,Self.Top,Self.Width,Self.Height]));
goodle 2003-09-13
  • 打赏
  • 举报
回复
请问是什么意思?
Eastunfail 2003-09-13
  • 打赏
  • 举报
回复
QueryDevice.SQL.Add(Format('where 编号="%d"',[DeviceID]));

2,496

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧