哪位DX能帮小弟我把这个语句改一下,原来是连ORACLE的,现在想连SQL SERVER,万分感谢!
哪位DX能帮我把这个语句改一下,原来是连ORACLE的,现在想连SQL SERVER,万分感谢!!
unit Ut_dump;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Db, DBTables, Grids, DBGrids,ComObj,IniFiles;
type
TForm1 = class(TForm)
Query1: TQuery;
Database1: TDatabase;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
var
dbname,user,pass,dir,code,sqlstr,filename,date,time:string;
myinifile:Tinifile;
section,key:TStrings;
i,j:integer;
sheet:variant;
excel:variant;
l,k:integer;
begin
myinifile:=Tinifile.create('datadump_tx_ylm.ini');
dbname:=myinifile.Readstring('config','dbname','a');
user :=myinifile.Readstring('config','user','a');
pass :=myinifile.Readstring('config','pass','a');
Database1.Close;
Database1.Params.Clear;
Database1.AliasName:= dbname;
Database1.Params.Add('USER NAME='+user);
Database1.Params.Add('PASSWORD='+pass);
Database1.Open;
section := TStringList.Create;
myinifile.readsections(section);
for i := 0 to section.Count-1 do
begin
if (section[i]<>'config') and (section[i]<>'path') and (section[i]<>'etmscode') then
begin
//showmessage(section[i]);
key := TStringList.Create;
myinifile.readsection(section[i],key);
excel:=createoleobject('excel.application');
excel.workbooks.add;
for j:=0 to key.Count-1 do
begin
//showmessage(key[j]);
sqlstr:=myinifile.Readstring(section[i],key[j],'a');
//ShowMessage(sqlstr);
excel.Workbooks[1].WorkSheets[j+1].Name:= key[j];
with Query1 do
begin
close;
sql.Clear;
sql.Add(sqlstr);
open;
sheet:=excel.workbooks[1].worksheets[j+1];
sheet.name:=key[j];
disablecontrols;
for l:=1 to fields.Count do
if fields[l-1].visible then
begin
sheet.cells[1,l]:=fields[l-1].DisplayLabel; //列标题
//ShowMessage(fields[l-1].DisplayLabel);
end;
first;
k:=2;
while not eof do
begin
for l:=1 to fields.Count do
if fields[l-1].visible then
begin
sheet.cells[k,l]:=fields[l-1].DisplayText; //列内容
//Sheet.rows[1].font.color:=clblue;)
end;
next;
inc(k);
end;
enablecontrols;
end;
end;
dir:=myinifile.Readstring('path','dir','a');
code:= myinifile.Readstring('etmscode','code','a');
filename:= dir+'\';
if section[i]= '销售' then filename:= filename+'SM_'+code+'_' else
begin
if section[i]='采购' then filename:= filename+'PM_'+code+'_' else
begin
if section[i]='库存' then filename:= filename+'IM_'+code+'_';
end;
end;
DateTimeToString(time,'yyyymmdd',now()-1);
unit Ut_dump;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Db, DBTables, Grids, DBGrids,ComObj,IniFiles;
type
TForm1 = class(TForm)
Query1: TQuery;
Database1: TDatabase;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
var
dbname,user,pass,dir,code,sqlstr,filename,date,time:string;
myinifile:Tinifile;
section,key:TStrings;
i,j:integer;
sheet:variant;
excel:variant;
l,k:integer;
begin
myinifile:=Tinifile.create('datadump_tx_ylm.ini');
dbname:=myinifile.Readstring('config','dbname','a');
user :=myinifile.Readstring('config','user','a');
pass :=myinifile.Readstring('config','pass','a');
Database1.Close;
Database1.Params.Clear;
Database1.AliasName:= dbname;
Database1.Params.Add('USER NAME='+user);
Database1.Params.Add('PASSWORD='+pass);
Database1.Open;
section := TStringList.Create;
myinifile.readsections(section);
for i := 0 to section.Count-1 do
begin
if (section[i]<>'config') and (section[i]<>'path') and (section[i]<>'etmscode') then
begin
//showmessage(section[i]);
key := TStringList.Create;
myinifile.readsection(section[i],key);
excel:=createoleobject('excel.application');
excel.workbooks.add;
for j:=0 to key.Count-1 do
begin
//showmessage(key[j]);
sqlstr:=myinifile.Readstring(section[i],key[j],'a');
//ShowMessage(sqlstr);
excel.Workbooks[1].WorkSheets[j+1].Name:= key[j];
with Query1 do
begin
close;
sql.Clear;
sql.Add(sqlstr);
open;
sheet:=excel.workbooks[1].worksheets[j+1];
sheet.name:=key[j];
disablecontrols;
for l:=1 to fields.Count do
if fields[l-1].visible then
begin
sheet.cells[1,l]:=fields[l-1].DisplayLabel; //列标题
//ShowMessage(fields[l-1].DisplayLabel);
end;
first;
k:=2;
while not eof do
begin
for l:=1 to fields.Count do
if fields[l-1].visible then
begin
sheet.cells[k,l]:=fields[l-1].DisplayText; //列内容
//Sheet.rows[1].font.color:=clblue;)
end;
next;
inc(k);
end;
enablecontrols;
end;
end;
dir:=myinifile.Readstring('path','dir','a');
code:= myinifile.Readstring('etmscode','code','a');
filename:= dir+'\';
if section[i]= '销售' then filename:= filename+'SM_'+code+'_' else
begin
if section[i]='采购' then filename:= filename+'PM_'+code+'_' else
begin
if section[i]='库存' then filename:= filename+'IM_'+code+'_';
end;
end;
DateTimeToString(time,'yyyymmdd',now()-1);