delphi 字符串转换问题

zhang88107 2020-03-01 10:56:55
for i :=2 to ExcelRowCount do
begin
if length(trim(Sheet.Cells[i,1 ].Value)) <=0 then break;
With ADOQuery1 do
begin
close;
SQL.Clear;
SQL.text:=('Select * from ICSale where FHeadSelfI0461= '''+ strtointDef(Sheet.Cells[i,1].Value,0)+'''');

因为字符段是int型的,而导入的excel 第一行为标题行,无法把列属性改为数值型,之前报错,把sql.add 转换为sql.text 正常了,但是需要把字符类型改为int型,用strtoint 或者strtointdef 都报错
[错误] Unit1.pas(91): Incompatible types: 'String' and 'Integer' excel里面绝对是int型数据
...全文
523 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_41908518 2020-03-17
  • 打赏
  • 举报
回复
'Select * from ICSale where FHeadSelfI0461= '''+ strtointDef(Sheet.Cells[i,1].Value,0)+'''' 引号多了对,=后面的不是字符了
改为 'Select * from ICSale where FHeadSelfI0461= ''+ strtointDef(Sheet.Cells[i,1].Value,0)+'''
JohnYale 2020-03-03
  • 打赏
  • 举报
回复
strtointDef(Sheet.Cells[i,1].Value,0) 这里用错函数了吧 这个函数返回值不是字符串类型
  • 打赏
  • 举报
回复
用参数化查询:
ADOQuery1.SQL.text := 'Select * from ICSale where FHeadSelfI0461= :FHeadSelfI0461';
ADOQuery1.Parameters.ParamByName('FHeadSelfI0461').Value := Sheet.Cells[i,1].Value;
tanqth 2020-03-02
  • 打赏
  • 举报
回复
Sheet.Cells[i,1].Value是什么类型?

2,497

社区成员

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

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