with tadoquery.Create(application) do begin Connection:= 你的SQLSERVE连接; close; sql.Clear; sql.Add('select * into 临时表 from OpenRowSet(''microsoft.jet.oledb.4.0'',''Excel 8.0;HDR=yes;database=EXCEL文件全路径;'',''select * from [Sheet1$]'')'); execsql; close; free; end; 剩下来得应该就不用说了. 这里有两点要注意, excel的第一行读不到的. EXCEL文件需要在与SQLSERVER同一机器上.
CLose;
SQL.Clear;
SQL.add(insert 1.............
SQL.add(insert 2.............
SQL.add(insert 3.............
SQL.add(insert 4.............
................
SQL.ExcuSQL;
把所有的insert语句写成一个,然后提交.
另外,最好使用事务.
begin
Connection:= 你的SQLSERVE连接;
close;
sql.Clear;
sql.Add('select * into 临时表 from OpenRowSet(''microsoft.jet.oledb.4.0'',''Excel 8.0;HDR=yes;database=EXCEL文件全路径;'',''select * from [Sheet1$]'')');
execsql;
close;
free;
end;
剩下来得应该就不用说了.
这里有两点要注意,
excel的第一行读不到的.
EXCEL文件需要在与SQLSERVER同一机器上.
我写了一个是先在access中建一个临时表,将excel的数据读到access的临时表中,再进行导入操作。挺快的
你还可以选择直接添加导入,更新导入,添加更新同时导入。