帮我看一下哪儿错了,非常感谢(30分)

  • 主题发起人 主题发起人 出现派
  • 开始时间 开始时间

出现派

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.exporttoexcel;
var
excelapp1,sheet1:variant;
i:integer;
s:string;
begin
try
excelapp1:=createoleobject('excel.application');
excelapp1.workbooks.add;
sheet1:=excelapp1.workbooks[1].worksheets[1];
with query2 do
begin
close;
sql.Clear;
sql.Add('select * from excel2');
open;
First;
i:=1;
end;

while not query2.Eof do
begin
s:=query2.Fields[0].AsString;
with query1 do
begin
close;
sql.Clear;
sql.Add('select * into excel3 from excel1 where 產品型號='+''''+s+'''');
open;
end;
with query3 do
begin
close;
sql.Clear;
sql.add('select * from excel3');
open;
end;
sheet1.cells[i,1]:=query3.Fields[0].AsString;
sheet1.cells[i,2]:=query3.Fields[2].AsString;
with query3 do
begin
close;
sql.Clear;
sql.add('select sum(結存數量) from excel3');
open;
sheet1.cells[i,3]:=query3.Fields[0].AsFloat;
end;
with query3 do
begin
close;
sql.Clear;
sql.add('drop table excel3');
open;
end;
next;
inc(i);
end;
if not excelapp1.activeworkbook.saved then
excelapp1.activesheet.saveas(editsave.Text);
Messagebox(handle,'導出數據成功!','提示',mb_ok);
excelapp1.quit;
except
Messagebox(handle,'導出數據失敗!','錯誤',mb_ok);
excelapp1.quit;
end;
end;
代码:

运行时提示有错,大概是是这样的:Query1:Command Text does not return a result set.
 
query1 中用的是select into ,是不返回结果集的,因此不能用open。要用query1.ExecSQL.
也就是说:你原来的代码如下:
sql.Add('select * into excel3 from excel1 where 產品型號='+''''+s+'''');
open;
改成
sql.Add('select * into excel3 from excel1 where 產品型號='+''''+s+'''');
ExecSQL;
就可以了
 

Similar threads

I
回复
0
查看
547
import
I
I
回复
0
查看
618
import
I
I
回复
0
查看
3K
import
I
I
回复
0
查看
974
import
I
I
回复
0
查看
3K
import
I
后退
顶部