DELPHI中数据批量插入的问题

来源:百度知道 编辑:UC知道 时间:2024/05/06 12:29:05
我添加了一个StringGrid的空间 想用一个FOR循环来依次将表格里面的数据添加到表中 代码怎么写 下面是我的代码 老是出错

procedure TForm11.SpeedButton1Click(Sender: TObject);
var
i:Integer;
begin
For i:=1 to StringGrid1.RowCount-1 do
begin
With ADOQuery1 do
begin
close;
sql.Clear;
sql.Add('insert into 成绩表(Name,Num,Chinese,Math,English,Physical,Chemistry) VALUES('''+StringGrid1.Cells[1,i]+''','''+StringGrid1.Cells[2,i]+''','''+StringGrid1.Cells[3,i]+''','''+StringGrid1.Cells[4,i]+''','''+StringGrid1.Cells[5,i]+''','''+StringGrid1.Cells[6,i]+''','''+StringGrid1.Cells[7,i]+''')');
open;
end;
end;
adotable1.Active:=false;
adotable1.Active:=true;
end;
哪位大侠知道的来帮忙弄一下~~

open是用来打开查询结果集的,例如,sql语句内容是select * from ……不涉及数据变动的,可以使用open;
ExecSQL用来执行对数据的操作,Insert,update,delete这类操作使用ExecSQL来执行。

open;
改为:Execsql;
sql语句好好看一下。