因为系统升级原因,需要将所用到的“零售管理”软件里面的商品库存报表里面的数据全部都给导出来(导出为EXECL格式),
以备升级后再次导入新的系统之中;
所用到的数据库是SQL 2000
需求各种能将EXECL表中数据全部导入到SQL 2000数据中,并且能在我升级后的“零售管理”软件中的库存中能再次看见?
备注:
网络上搞的别人“山寨版”的代码就别告诉了我了,谢谢!o(∩_∩)o...哈哈!
6 个解决方案
#1
导入EXCEL文件的数据:
SELECT a.* into 表名
FROM openrowset('Microsoft.Jet.OLEDB.4.0','Excel 5.0;hdr=Yes;DataBase=盘符(路径):\文件名.xls',工作表名$)
AS a
GO
#2
如果是多个,就直接使用sql 2000的导入导出(DTS)功能,注意选对数据源和需要插入或创建的表即可.
如果是语句,就用一楼的代码.
#3
begin
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('select * from T_RES_ECO_PASS');
ADOQuery1.Open;
SMImportFromXLS.SourceFileName:=RzButtonEdit2.Text;
SMImportFromXLS.Mappings.Clear;
SMImportFromXLS.Mappings.Add('WKO_TYPE=A');
SMImportFromXLS.Mappings.Add('SendData=B');
SMImportFromXLS.Mappings.Add('ECONO=C');
SMImportFromXLS.Mappings.Add('subject=D');
SMImportFromXLS.Mappings.Add('EcrNo=E');
SMImportFromXLS.Mappings.Add('ECOCC=F');
SMImportFromXLS.Mappings.Add('Model=G');
try
SMImportFromXLS.Execute;
InsertECOLOG;
except
MessageDlg('請選擇要導入的Excel檔案!',mtWarning,[mbOK],0);
Exit;
end;
adosrp_eco.ExecProc;
RefreshECO;
ESPStoredProcedure;
end;
#4
procedure TRES_DCC_ECRN_F.Button1Click(Sender: TObject);
var
WorkBk,Eapp:OleVariant;
begin
inherited;
if RzButtonEdit2.Text <>'' then
begin
if (ExtractFileExt(RzButtonEdit2.Text)<>'.xls') then
begin
MessageDlg('請選擇要導入的Excel檔案!',mtWarning,[mbOK],0);
RzButtonEdit2.Clear;
end
else
begin
try
Application.ProcessMessages;
Eapp:=CreateOleObject('Excel.Application');
WorkBk:=Eapp.WorkBooks.Open(RzButtonEdit2.Text);
Eapp.Visible:=False;
aa:=Eapp.Cells[3,3].Value;
if ((Copy(Trim(aa),1,3)<>'ECO')) and ((Copy(Trim(aa),1,3)<>'DCO')) then
begin
MessageDlg('檔案格式錯誤!',mtWarning,[mbOK],0);
InsertECOErrorLOG;
Exit;
end;
finally
Eapp.ActiveWorkBook.Saved:=True;
WorkBk.Close;
Eapp.Quit;
Application.ProcessMessages;
end;
with ADOQuery1 do
begin
Close;
SQL.Text:='select * from T_RES_ECO_PASS where ECONO='''+ aa+'''';
Open;
if RecordCount=1 then
begin
MessageDlg('請檢查:導入檔案時編號"'+ aa+'"的記錄重復!',mtWarning,[mbOK],0);
InsertECORepeatLOG;
Screen.Cursor:=crDefault;
Exit;
end;
end;
begin
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('select * from T_RES_ECO_PASS');
ADOQuery1.Open;
SMImportFromXLS.SourceFileName:=RzButtonEdit2.Text;
SMImportFromXLS.Mappings.Clear;
SMImportFromXLS.Mappings.Add('WKO_TYPE=A');
SMImportFromXLS.Mappings.Add('SendData=B');
SMImportFromXLS.Mappings.Add('ECONO=C');
SMImportFromXLS.Mappings.Add('subject=D');
SMImportFromXLS.Mappings.Add('EcrNo=E');
SMImportFromXLS.Mappings.Add('ECOCC=F');
SMImportFromXLS.Mappings.Add('Model=G');
try
SMImportFromXLS.Execute;
InsertECOLOG;
except
MessageDlg('請選擇要導入的Excel檔案!',mtWarning,[mbOK],0);
Exit;
end;
adosrp_eco.ExecProc;
RefreshECO;
ESPStoredProcedure;
end;
end;
end
else
begin
MessageDlg('請選擇要導入的Excel檔案!',mtWarning,[mbOK],0);
Exit;
end;
end;
#5
--excel to sql:
SELECT a.* into 表名
FROM openrowset('Microsoft.Jet.OLEDB.4.0','Excel 5.0;hdr=Yes;DataBase=盘符(路径):\文件名.xls',工作表名$)
AS a
GO
--sql to excel:
EXEC master..xp_cmdshell 'bcp MES.dbo.abc out c:\test.xls -c -q -S"172.20.100.22" -U"MES" -P"MES"'
#6
数据库目标->导入数据->选择数据源(excel)->数据库目标->完成!
#1
导入EXCEL文件的数据:
SELECT a.* into 表名
FROM openrowset('Microsoft.Jet.OLEDB.4.0','Excel 5.0;hdr=Yes;DataBase=盘符(路径):\文件名.xls',工作表名$)
AS a
GO
#2
如果是多个,就直接使用sql 2000的导入导出(DTS)功能,注意选对数据源和需要插入或创建的表即可.
如果是语句,就用一楼的代码.
#3
begin
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('select * from T_RES_ECO_PASS');
ADOQuery1.Open;
SMImportFromXLS.SourceFileName:=RzButtonEdit2.Text;
SMImportFromXLS.Mappings.Clear;
SMImportFromXLS.Mappings.Add('WKO_TYPE=A');
SMImportFromXLS.Mappings.Add('SendData=B');
SMImportFromXLS.Mappings.Add('ECONO=C');
SMImportFromXLS.Mappings.Add('subject=D');
SMImportFromXLS.Mappings.Add('EcrNo=E');
SMImportFromXLS.Mappings.Add('ECOCC=F');
SMImportFromXLS.Mappings.Add('Model=G');
try
SMImportFromXLS.Execute;
InsertECOLOG;
except
MessageDlg('請選擇要導入的Excel檔案!',mtWarning,[mbOK],0);
Exit;
end;
adosrp_eco.ExecProc;
RefreshECO;
ESPStoredProcedure;
end;
#4
procedure TRES_DCC_ECRN_F.Button1Click(Sender: TObject);
var
WorkBk,Eapp:OleVariant;
begin
inherited;
if RzButtonEdit2.Text <>'' then
begin
if (ExtractFileExt(RzButtonEdit2.Text)<>'.xls') then
begin
MessageDlg('請選擇要導入的Excel檔案!',mtWarning,[mbOK],0);
RzButtonEdit2.Clear;
end
else
begin
try
Application.ProcessMessages;
Eapp:=CreateOleObject('Excel.Application');
WorkBk:=Eapp.WorkBooks.Open(RzButtonEdit2.Text);
Eapp.Visible:=False;
aa:=Eapp.Cells[3,3].Value;
if ((Copy(Trim(aa),1,3)<>'ECO')) and ((Copy(Trim(aa),1,3)<>'DCO')) then
begin
MessageDlg('檔案格式錯誤!',mtWarning,[mbOK],0);
InsertECOErrorLOG;
Exit;
end;
finally
Eapp.ActiveWorkBook.Saved:=True;
WorkBk.Close;
Eapp.Quit;
Application.ProcessMessages;
end;
with ADOQuery1 do
begin
Close;
SQL.Text:='select * from T_RES_ECO_PASS where ECONO='''+ aa+'''';
Open;
if RecordCount=1 then
begin
MessageDlg('請檢查:導入檔案時編號"'+ aa+'"的記錄重復!',mtWarning,[mbOK],0);
InsertECORepeatLOG;
Screen.Cursor:=crDefault;
Exit;
end;
end;
begin
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('select * from T_RES_ECO_PASS');
ADOQuery1.Open;
SMImportFromXLS.SourceFileName:=RzButtonEdit2.Text;
SMImportFromXLS.Mappings.Clear;
SMImportFromXLS.Mappings.Add('WKO_TYPE=A');
SMImportFromXLS.Mappings.Add('SendData=B');
SMImportFromXLS.Mappings.Add('ECONO=C');
SMImportFromXLS.Mappings.Add('subject=D');
SMImportFromXLS.Mappings.Add('EcrNo=E');
SMImportFromXLS.Mappings.Add('ECOCC=F');
SMImportFromXLS.Mappings.Add('Model=G');
try
SMImportFromXLS.Execute;
InsertECOLOG;
except
MessageDlg('請選擇要導入的Excel檔案!',mtWarning,[mbOK],0);
Exit;
end;
adosrp_eco.ExecProc;
RefreshECO;
ESPStoredProcedure;
end;
end;
end
else
begin
MessageDlg('請選擇要導入的Excel檔案!',mtWarning,[mbOK],0);
Exit;
end;
end;
#5
--excel to sql:
SELECT a.* into 表名
FROM openrowset('Microsoft.Jet.OLEDB.4.0','Excel 5.0;hdr=Yes;DataBase=盘符(路径):\文件名.xls',工作表名$)
AS a
GO
--sql to excel:
EXEC master..xp_cmdshell 'bcp MES.dbo.abc out c:\test.xls -c -q -S"172.20.100.22" -U"MES" -P"MES"'
#6
数据库目标->导入数据->选择数据源(excel)->数据库目标->完成!