用bcp导,给你帖段代码看看先,以前做的.
unit ufrmBill;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls, Buttons;
type
TfrmBill = class(TForm)
btnExport: TBitBtn;
procedure btnExportClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmBill: TfrmBill;
procedure TfrmBill.btnExportClick(Sender: TObject);
var
sSQL,sTable: string;
bCreateProcess: Boolean;
lpStartupInfo: TStartupInfo;
lpProcessInfo: TProcessInformation;
begin
sSQL := 'bcp ' + DM.scData.Params.Values['DataBaseName'] + '..' + sTable+ //DataBase数据库名, sTable表名
' out ' + DM.sdBillfile.FileName +
' -S' + DM.scData.Params.Values['ServerName'] + //服务器名
' -U' + DM.scData.Params.Values['UserName'] + //用户名
' -P' + DM.scData.Params.Values['Password'] + //密码
' -c -t ,';
FillChar(lpStartupInfo, Sizeof(StartupInfo), #0);
lpStartupInfo.cb := Sizeof(StartupInfo);
lpStartupInfo.dwFlags := STARTF_USESHOWWINDOW;
lpStartupInfo.wShowWindow := SW_SHOW;
bCreateProcess := CreateProcessA(nil, PChar(sSQL), //创建进程,执行导出
nil, nil, True, NORMAL_PRIORITY_CLASS, nil, nil,
lpStartupInfo, lpProcessInfo);
if bCreateProcess then
begin
WaitForSingleObject(lpProcessInfo.hProcess, INFINITE);
CloseHandle(lpProcessInfo.hProcess);
CloseHandle(lpProcessInfo.hThread);
end
else
begin
Application.MessageBox(PChar('导出数据失败!请检查文件bcp.exe是否存在!'), '导出错误', MB_ICONERROR);
Exit;
end;
Application.MessageBox('导出数据完成!', '导出完成', MB_ICONINFORMATION);
end;
end