SQL Server 和 Access 數(shù)據(jù)導(dǎo)入導(dǎo)出
見很多新入門學(xué)編程的朋友,都問同一個(gè)問題,現(xiàn)在把我個(gè)人開發(fā)中用到的方法公布如下,您有好的想法請(qǐng)多多交流。
一、下面是用存儲(chǔ)過程導(dǎo)入ACCESS數(shù)據(jù)到SQL SERVER數(shù)據(jù)庫(kù),代碼少。
CREATE PROCEDURE PPED
@TN varchar(50)
?AS
??? select? *? into #temp1 from Opendatasource('Microsoft.Jet.OLEDB.4.0','Data Source="D:/Excel2007/28.xls";Extended Properties=Excel 5.0;Persist Security
Info=false')...sheet1$
?? select? 序號(hào) as orderNO,貨號(hào) as ProductNO,品名 as ProductName ,規(guī)格 as Specification ,單位 as Unit,數(shù)量 as Quantity,完成 as finished,備注 as Remark from #temp1
二、一、下面是用存儲(chǔ)過程導(dǎo)出SQL SERVER 數(shù)據(jù)到數(shù)據(jù)庫(kù) ACCESS,在Delphi7 里寫代碼比較少。
導(dǎo)出EXCEL:
procedure? OuttoExcel4(const sFileName:string;sDataSet:TDataSet;Grid:TDBGrid);
procedure? OuttoExcel4(const sFileName:string;sDataSet:TDataSet;Grid:TDBGrid);
var
? v: variant;
? i,j: integer;
begin
??? v := CreateOLEObject('Excel.Application');
??? v.WorkBooks.Add;
??? v.Visible := True;
??? Application.BringToFront;
??? try
??? try
??????? sDataSet.DisableControls;
??????? for i:=0 to Grid.FieldCount-1 do
??????? begin
?????????? v.goto('R1'+'C'+IntToStr(i+1));
?????????? v.ActiveCell.FormulaR1C1 := Grid.Columns[i].Title.Caption;
??????? end;
??????? j:=2;
??????? sDataSet.First;
??????? while not sDataSet.Eof do
??????? begin
?????????? for i:=0 to Grid.FieldCount-1 do
?????????? begin
????????????? v.goto('R'+IntToStr(j)+'C'+IntToStr(i+1));
????????????? v.ActiveCell.FormulaR1C1 := sDataSet.FieldByName(Grid.Columns[i].fieldname).AsString;
?????????? end;
?????????? sDataSet.Next;
?????????? j:=j+1;
??????? end;
??? except
??? end;
??? finally
?????? sDataSet.First;
?????? sDataSet.EnableControls;
?????? v.quit;
??? end;
end;?
以上代碼在 Delphi7+SQL Server2000 中編譯通過。