TSTRINGGRIP + UPDATE SQL 问题

szeyin 2012-09-04 09:35:22
EXCEL檔有2栏 : keyno, partno
sql table tpadea 主要有 2栏 : dea001 及 dea004

载入excel檔到 Tstringgrid1(已弄好), 每一行与tpadea 比較, 如找到相同的key(dea001); 就更新tpadea的partno(DEA004) 为 tstringgrip的partno. (StringGrid1.Cells[7, r])

以下方法失敗, 请问应该怎样更正? 谢谢.

procedure TForm1.Button1Click(Sender: TObject);
var
r: Integer;
begin
For r := 1 to StringGrid1.RowCount - 1 do
with ADOQuery1 do
begin
Active := false;
SQL.Clear;
SQL.Add('UPDATE TPADEA');
SQL.Add('SET DEA004 = StringGrid1.Cells[7, r] WHERE DEA001=StringGrid1.Cells[5, r]');
ExecSQL
end;
ADOQuery1.Refresh;
end;
end.
...全文
78 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
szeyin 2012-09-04
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

Delphi(Pascal) code
SQL.Add('SET DEA004 = '+Quotedstr(StringGrid1.Cells[7, r])+' WHERE DEA001='+Quotedstr(StringGrid1.Cells[5, r]));
[/Quote]

....Cannot perform this operation on a closed dataset..process stopped.
szeyin 2012-09-04
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 的回复:]

1楼就是正确答案了...前提是你的字段类型都是字符串.
[/Quote]

1 DRAG BUTTON ASS'Y 大鈕裝配 –913645–F 6WD055010 OPUS 4500BRi -913645-F
2 SPOOL ASS'Y 線轆裝配 –400918–F 6WD056010 OPUS 4500BRi -400918-F
3
4
5
.
.
.

全是字串
szeyin 2012-09-04
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

Delphi(Pascal) code
SQL.Add('SET DEA004 = '+Quotedstr(StringGrid1.Cells[7, r])+' WHERE DEA001='+Quotedstr(StringGrid1.Cells[5, r]));
[/Quote]

无更新
robotdeng 2012-09-04
  • 打赏
  • 举报
回复
用Showmessage(SQL.text); 查看你的SQL命令是否正确.
robotdeng 2012-09-04
  • 打赏
  • 举报
回复
1楼就是正确答案了...前提是你的字段类型都是字符串.
szeyin 2012-09-04
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

Delphi(Pascal) code
SQL.Add('SET DEA004 = '+Quotedstr(StringGrid1.Cells[7, r])+' WHERE DEA001='+Quotedstr(StringGrid1.Cells[5, r]));
[/Quote]

仍然是石沉大海.
haitao 2012-09-04
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]
Delphi(Pascal) code
如果DEA001字段类型是整数
SQL.Add('SET DEA004 = StringGrid1.Cells[7, r] WHERE DEA001='+StringGrid1.Cells[5, r]);

如果DEA001字段类型是字符串
SQL.Add('SET DEA004 = StringGrid1.Cells[7, r] WHERE DE……
[/Quote]

哦,set DEA004=后的内容也要类似处理
haitao 2012-09-04
  • 打赏
  • 举报
回复
如果DEA001字段类型是整数
SQL.Add('SET DEA004 = StringGrid1.Cells[7, r] WHERE DEA001='+StringGrid1.Cells[5, r]);

如果DEA001字段类型是字符串
SQL.Add('SET DEA004 = StringGrid1.Cells[7, r] WHERE DEA001='+quotedstr(StringGrid1.Cells[5, r]));
kaikai_kk 2012-09-04
  • 打赏
  • 举报
回复
SQL.Add('SET DEA004 = '+Quotedstr(StringGrid1.Cells[7, r])+' WHERE DEA001='+Quotedstr(StringGrid1.Cells[5, r]));

2,498

社区成员

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

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