EXCEL导入MSSQL总是最后一行未导入
var
i : integer;
begin
if messagebox(Self.Handle,'你确定要提交下面表格的数据吗?','系统提示',mb_yesno+mb_iconquestion)=idyes then
begin
a := GetTickCount;
adoquery2.close;
adoquery2.sql.text := 'select * from LenLoading where 1=2';
adoquery2.open;
b := GetTickCount;
if inttostr(AdoQuery1.Fields.Count)=inttostr(AdoQuery2.Fields.Count) then
begin
AdoQuery1.FindFirst;
if not AdoQuery1.isEmpty then begin
with AdoQuery1 do while not eof do begin
AdoQuery2.Append;
for I := 0 to AdoQuery1.fieldCount -1 do
begin
AdoQuery2.fields[i].value := Fields[i].value;
end;
Next;
end;
StatusBar1.Panels[0].Text:=('导入数据量:'+inttostr(AdoQuery1.RecordCount));
end;
end
else
begin
StatusBar1.Panels[0].Text:='EXCEL表字段与远程数据库表字段不一至,请核对后重新提交数据';
end;
end;
AdoQuery1 是读取的EXCEL数据,AdoQuery2链接的是MSSQL,导入的EXCEL数据总是最后一行没有导入
[解决办法]
缺少提交语句
with AdoQuery1 do while not eof do begin
AdoQuery2.Append;
for I := 0 to AdoQuery1.fieldCount -1 do
begin
AdoQuery2.fields[i].value := Fields[i].value;
end;
Next;
AdoQuery2.post; --添加
end;