📄 unit1.pas
字号:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB, Buttons, Grids, DBGrids, OleServer, ExcelXP;
type
TForm1 = class(TForm)
GroupBox1: TGroupBox;
Button1: TButton;
Button2: TButton;
Button3: TButton;
ADOConnection1: TADOConnection;
ADOConnection2: TADOConnection;
ADOConnection3: TADOConnection;
Button4: TButton;
ADOConnection4: TADOConnection;
Button5: TButton;
Button7: TButton;
ADOConnection7: TADOConnection;
ADOConnection5: TADOConnection;
Button6: TButton;
ADOConnection6: TADOConnection;
Button8: TButton;
ADOConnection8: TADOConnection;
Button9: TButton;
ADOConnection9: TADOConnection;
GroupBox2: TGroupBox;
Button10: TButton;
ADOConnection10: TADOConnection;
ADOConnection11: TADOConnection;
Button11: TButton;
Button12: TButton;
ADOConnection12: TADOConnection;
Button13: TButton;
ADOConnection13: TADOConnection;
Button14: TButton;
ADOConnection14: TADOConnection;
Button15: TButton;
ADOConnection15: TADOConnection;
Button16: TButton;
ADOConnection16: TADOConnection;
ADOConnection17: TADOConnection;
Button17: TButton;
Button18: TButton;
ADOConnection18: TADOConnection;
Button19: TButton;
ADOConnection19: TADOConnection;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button8Click(Sender: TObject);
procedure Button9Click(Sender: TObject);
procedure Button10Click(Sender: TObject);
procedure Button11Click(Sender: TObject);
procedure Button12Click(Sender: TObject);
procedure Button13Click(Sender: TObject);
procedure Button14Click(Sender: TObject);
procedure Button15Click(Sender: TObject);
procedure Button16Click(Sender: TObject);
procedure Button17Click(Sender: TObject);
procedure Button18Click(Sender: TObject);
procedure Button19Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
try
ADOConnection1.Execute('Select * Into [Text;Database=c:\temp].tax.txt From Zlyfp');
Application.MessageBox('导出数据成功 !', PChar('数据导入导出提示'), MB_OK +
MB_ICONINFORMATION + MB_TOPMOST);
except
Application.MessageBox('导出数据失败 !', PChar('数据导入导出提示'), MB_OK +
MB_ICONINFORMATION + MB_TOPMOST);
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
try
ADOConnection2.Connected := True;
ADOConnection2.Execute('Select * Into abc From [Text;Database=c:\temp].tax.txt');
Application.MessageBox('导出数据成功 !', PChar('数据导入导出提示'), MB_OK +
MB_ICONINFORMATION + MB_TOPMOST);
except
Application.MessageBox('导出数据失败 !', PChar('数据导入导出提示'), MB_OK +
MB_ICONINFORMATION + MB_TOPMOST);
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
var
sSql : string ;
begin
try
ADOConnection3.Connected := False;
ADOConnection3.Connected := true;
{把 ACCESS 中的表 abcd 导出为 Zlyfp.dbf}
sSql := 'select * into Zlyfp in ''c:\temp'' ''DBASE III;'' from abcd ' ;
ADOConnection3.Execute(sSql ) ;
Application.MessageBox('导出数据成功 !', PChar('数据导入导出提示'), MB_OK +
MB_ICONINFORMATION + MB_TOPMOST);
except
Application.MessageBox('导出数据失败 !', PChar('数据导入导出提示'), MB_OK +
MB_ICONINFORMATION + MB_TOPMOST);
end;
end;
procedure TForm1.Button4Click(Sender: TObject);
var
sSql : string ;
begin
try
ADOConnection4.Connected := False;
ADOConnection4.Connected := true;
{把 Zlyfp.dbf 导出为 ACCESS 中的表 abcd }
sSql := 'select * into abcd from Zlyfp in ''c:\temp'' ''dbase 5.0;'' ' ;
ADOConnection4.Execute(sSql ) ;
Application.MessageBox('导出数据成功 !', PChar('数据导入导出提示'), MB_OK +
MB_ICONINFORMATION + MB_TOPMOST);
except
Application.MessageBox('导出数据失败 !', PChar('数据导入导出提示'), MB_OK +
MB_ICONINFORMATION + MB_TOPMOST);
end;
end;
procedure TForm1.Button5Click(Sender: TObject);
var
sSql : string ;
begin
try
ADOConnection5.Connected := False ;
ADOConnection5.Connected := true ;
sSql :=
'INSERT INTO aaa (prd_no, SPC, UT, DFU_UT, KND, IDX1, NAME, SUP1)' + //prd_no, SPC, UT, DFU_UT, KND, IDX1, NAME, SUP1
' SELECT' +
' prd_no, SPC, UT, DFU_UT, KND, IDX1, NAME, SUP1' +
' FROM [excel 8.0;database=C:\temp\LW.xls].[PRDT$]';
ADOConnection5.Execute(sSql ) ;
Application.MessageBox('导出数据成功 !', PChar('数据导入导出提示'), MB_OK +
MB_ICONINFORMATION + MB_TOPMOST);
except
Application.MessageBox('导出数据失败 !', PChar('数据导入导出提示'), MB_OK +
MB_ICONINFORMATION + MB_TOPMOST);
end;
end;
procedure TForm1.Button7Click(Sender: TObject);
var
ssql : string ;
begin
try
ssql := 'select * into file in ''C:\temp\File.mdb'' from abcd ' ;
ADOConnection7.Connected := true;
ADOConnection7.Execute(ssql);
Application.MessageBox('导出数据成功 !', PChar('数据导入导出提示'), MB_OK +
MB_ICONINFORMATION + MB_TOPMOST);
except
Application.MessageBox('导出数据失败 !', PChar('数据导入导出提示'), MB_OK +
MB_ICONINFORMATION + MB_TOPMOST);
end;
end;
procedure TForm1.Button6Click(Sender: TObject);
var
sSql : string ;
begin
try
ADOConnection6.Connected := False ;
ADOConnection6.Connected := true ;
sSql :='Select * into sheet1 in "C:\temp\Temp.xls" "Excel 8.0;" from aaa';
ADOConnection6.Execute(sSql ) ;
Application.MessageBox('导出数据成功 !', PChar('数据导入导出提示'), MB_OK +
MB_ICONINFORMATION + MB_TOPMOST);
except
Application.MessageBox('导出数据失败 !', PChar('数据导入导出提示'), MB_OK +
MB_ICONINFORMATION + MB_TOPMOST);
end;
end;
procedure TForm1.Button8Click(Sender: TObject);
var
sSql : string ;
begin
try
ADOConnection8.Connected := False;
ADOConnection8.Connected := true;
{把 ACDB.DB 导出为 ACCESS 中的表 db }
sSql := 'select * into bd from ACDB in ''c:\temp'' ''Paradox 7.X;'' ' ;
ADOConnection8.Execute(sSql ) ;
Application.MessageBox('导出数据成功 !', PChar('数据导入导出提示'), MB_OK +
MB_ICONINFORMATION + MB_TOPMOST);
except
Application.MessageBox('导出数据失败 !', PChar('数据导入导出提示'), MB_OK +
MB_ICONINFORMATION + MB_TOPMOST);
end;
end;
procedure TForm1.Button9Click(Sender: TObject);
var
sSql : string ;
begin
try
ADOConnection8.Connected := False;
ADOConnection8.Connected := true;
{把 ACCESS 中的表 db 导出为 ACDB.DB }
sSql := 'select * into ACDBEF in ''c:\temp'' ''Paradox 7.X;'' from bd' ;
ADOConnection8.Execute(sSql ) ;
Application.MessageBox('导出数据成功 !', PChar('数据导入导出提示'), MB_OK +
MB_ICONINFORMATION + MB_TOPMOST);
except
Application.MessageBox('导出数据失败 !', PChar('数据导入导出提示'), MB_OK +
MB_ICONINFORMATION + MB_TOPMOST);
end;
end;
procedure TForm1.Button10Click(Sender: TObject);
var
Ssql :string ;
begin
try
ADOConnection10.Provider:='Microsoft.Jet.OLEDB.4.0;Data Source=c:\temp;Extended Properties="text;HDR=YES;";Persist Security Info=False' ;
Ssql :='SELECT * into SQLTXT.txt FROM Zlyfp IN [ODBC]' +
'[ODBC;Driver=SQL Server;UID=;PWD=;Server=program.;DataBase=yj;]' ;
ADOConnection10.Execute(Ssql );
Application.MessageBox('导出数据成功 !', PChar('数据导入导出提示'), MB_OK +
MB_ICONINFORMATION + MB_TOPMOST);
except
Application.MessageBox('导出数据失败 !', PChar('数据导入导出提示'), MB_OK +
MB_ICONINFORMATION + MB_TOPMOST);
end;
end;
procedure TForm1.Button11Click(Sender: TObject);
var
Ssql :string ;
begin
try
ADOConnection11.Provider:='Microsoft.Jet.OLEDB.4.0;Data Source=c:\temp;Extended Properties="text;HDR=YES;";Persist Security Info=False' ;
Ssql :='select * INTO Zlyfp1 FROM ' +
'OpenRowset(''MSDASQL'', ''Driver={Microsoft Text Driver (*.txt; *.csv)}; '+
'DefaultDir=c:\temp;'',''select * from SQLTXT.txt'')' ;
ADOConnection11.Execute(Ssql );
Application.MessageBox('导出数据成功 !', PChar('数据导入导出提示'), MB_OK +
MB_ICONINFORMATION + MB_TOPMOST);
except
Application.MessageBox('导出数据失败 !', PChar('数据导入导出提示'), MB_OK +
MB_ICONINFORMATION + MB_TOPMOST);
end;
end;
procedure TForm1.Button12Click(Sender: TObject);
var
sqll:string ;
begin
try
{ sqll := 'SELECT * into SQLabc FROM bank IN [ODBC]' +
' [ODBC;Driver=SQL Server;UID=tax;PWD=tax;Server=194.1.1.1.;DataBase=tax;]' ;}
ADOConnection12.Connected := False ;
ADOConnection12.Connected := True ;
sqll := 'SELECT * into SQLabc FROM Zlyfp IN [ODBC]' +
' [ODBC;Driver=SQL Server;UID=;PWD=;Server=program.;DataBase=YJ;]' ;
ADOConnection12.Execute(sqll ) ;
Application.MessageBox('导出数据成功 !', PChar('数据导入导出提示'), MB_OK +
MB_ICONINFORMATION + MB_TOPMOST);
except
Application.MessageBox('导出数据失败 !', PChar('数据导入导出提示'), MB_OK +
MB_ICONINFORMATION + MB_TOPMOST);
end;
end;
procedure TForm1.Button13Click(Sender: TObject);
var
sqll:string ;
begin
try
ADOConnection13.Connected := False ;
ADOConnection13.Connected := True ;
sqll := 'select * into Zlyfp2 from OPENDATASOURCE (''Microsoft.Jet.OLEDB.4.0'', ' +
'''Data Source=c:\temp\test.mdb;Persist Security Info=false;Jet OLEDB:Database Password=;''' +
' )...SQLabc' ;
ADOConnection13.Execute(sqll ) ;
Application.MessageBox('导出数据成功 !', PChar('数据导入导出提示'), MB_OK +
MB_ICONINFORMATION + MB_TOPMOST);
except
Application.MessageBox('导出数据失败 !', PChar('数据导入导出提示'), MB_OK +
MB_ICONINFORMATION + MB_TOPMOST);
end;
end;
procedure TForm1.Button14Click(Sender: TObject);
var
sqll:string ;
begin
try
ADOConnection14.Provider :='Microsoft.Jet.OLEDB.4.0;Data Source=C:\TEMP\TempXY.xls;Extended Properties=Excel 8.0' ;
ADOConnection14.Connected := False ;
ADOConnection14.Connected := True ;
sqll :='SELECT * into SQLEXCEL FROM Zlyfpxy IN [ODBC] [ODBC;Driver=SQL Server;UID=;PWD=;Server=program.;DataBase=yj;]';
ADOConnection14.Execute(sqll ) ;
Application.MessageBox('导出数据成功 !', PChar('数据导入导出提示'), MB_OK +
MB_ICONINFORMATION + MB_TOPMOST);
except
Application.MessageBox('导出数据失败 !', PChar('数据导入导出提示'), MB_OK +
MB_ICONINFORMATION + MB_TOPMOST);
end;
end;
procedure TForm1.Button15Click(Sender: TObject);
var
sqll:string ;
begin
try
ADOConnection15.Provider :='Microsoft.Jet.OLEDB.4.0;Data Source=C:\temp\Temp.xls;Extended ' +
'Properties="Excel 8.0;HDR=Yes;";Persist Security Info=False' ;
ADOConnection15.Connected := False ;
ADOConnection15.Connected := True ;
sqll := 'SELECT * into SQLEXCEL FROM ' +
'OpenDataSource(''Microsoft.Jet.OLEDB.4.0'',''Data Source="C:\temp\Temp.xls";Extended Properties="Excel 5.0;HDR=Yes;";Persist Security Info=False'')...sheet1$' ;
ADOConnection15.Execute(sqll ) ;
Application.MessageBox('导出数据成功 !', PChar('数据导入导出提示'), MB_OK +
MB_ICONINFORMATION + MB_TOPMOST);
except
Application.MessageBox('导出数据失败 !', PChar('数据导入导出提示'), MB_OK +
MB_ICONINFORMATION + MB_TOPMOST);
end;
end;
procedure TForm1.Button16Click(Sender: TObject);
var
sqll:string ;
begin
try
ADOConnection16.Provider :='Microsoft.Jet.OLEDB.4.0;Data Source=C:\temp\;Extended Properties=DBASE IV' ;
ADOConnection16.Connected := False ;
ADOConnection16.Connected := True ;
sqll :='SELECT * into SQLDB FROM Zlyfpxy IN [ODBC] [ODBC;Driver=SQL Server;UID=;PWD=;Server=program.;DataBase=yj;]';
ADOConnection16.Execute(sqll ) ;
Application.MessageBox('导出数据成功 !', PChar('数据导入导出提示'), MB_OK +
MB_ICONINFORMATION + MB_TOPMOST);
except
Application.MessageBox('导出数据失败 !', PChar('数据导入导出提示'), MB_OK +
MB_ICONINFORMATION + MB_TOPMOST);
end;
end;
procedure TForm1.Button17Click(Sender: TObject);
var
sqll:string ;
begin
//try
ADOConnection17.Provider :='Microsoft.Jet.OLEDB.4.0;Data Source=C:\temp\SQLDB.DBF;Extended ' +
'Properties="DBASE IV;HDR=Yes;";Persist Security Info=False' ;
ADOConnection17.Connected := False ;
ADOConnection17.Connected := True ;
sqll := 'SELECT * into SQLDB FROM ' +
'OpenDataSource(''Microsoft.Jet.OLEDB.4.0'',''Data Source="C:\temp\";Extended Properties="DBASE IV;HDR=Yes;";Persist Security Info=False'')...SQLDB' ;
ADOConnection17.Execute(sqll ) ;
Application.MessageBox('导出数据成功 !', PChar('数据导入导出提示'), MB_OK +
MB_ICONINFORMATION + MB_TOPMOST);
//except
// Application.MessageBox('导出数据失败 !', PChar('数据导入导出提示'), MB_OK +
// MB_ICONINFORMATION + MB_TOPMOST);
//end;
end;
procedure TForm1.Button18Click(Sender: TObject);
var
sqll:string ;
begin
ADOConnection18.Provider :='Microsoft.Jet.OLEDB.4.0;Data Source=c:\temp;Extended Properties="text;HDR=YES;";Persist Security Info=False' ;
sqll:= 'SELECT * into aaa.txt FROM Tab1 IN [ODBC]' +
' [ODBC;Driver={Microsoft ODBC for Oracle};UID=oracle;PWD=oracle;SERVER=yourdata;]' ;
ADOConnection18.Execute(sqll ) ;
end;
procedure TForm1.Button19Click(Sender: TObject);
var
sqll:string ;
begin
ADOConnection19.Provider :='Microsoft.Jet.OLEDB.4.0;Data Source=c:\temp\db1.mdb;Persist Security Info=False' ;
sqll:= 'SELECT * into tablename FROM Tab1 IN [ODBC] ' +
'[ODBC;Driver={Microsoft ODBC for Oracle};UID=oracle;PWD=oracle;SERVER=yourdata;] ' ;
ADOConnection19.Execute(sqll ) ;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -