各位大哥,問各困擾我好多天的問題.
我想將本地機上的excel2000文檔的數據導入到遠程服務器的sql server上,用ado怎麼實現.我設想的是button1click事件中打開dialog讓管理員在本地機上選擇要导入的excel2000文件,然後彈出提示框application.messageBox,確認ok后,excel中的數據就導入到遠程sql server的一個固定名字的表單中.儘量給出控件名都是默認的代碼.問題解決立即給分,不夠再加
我想將本地機上的excel2000文檔的數據導入到遠程服務器的sql server上,用ado怎麼實現.我設想的是button1click事件中打開dialog讓管理員在本地機上選擇要导入的excel2000文件,然後彈出提示框application.messageBox,確認ok后,excel中的數據就導入到遠程sql server的一個固定名字的表單中.儘量給出控件名都是默認的代碼.問題解決立即給分,不夠再加
异构数据库之间完全可以用SQL语句导数据。大家抛弃BatchMove吧 如果觉得好请Up一下,如果觉得不好也请Up一下 ( 积分:1, 回复:255, 阅读:5869 )
分类:数据库-C/S型 ( 版主:千中元, luyear ) 来自:碧血剑, 时间:2003-3-18 16:33:00, ID:1691966 [显示:小字体 | 大字体] 告诉你一个最快的方法,用SQLServer连接DBF
在SQLServer中执行
SELECT * into bmk
FROM OpenDataSource( 'Microsoft.Jet.OLEDB.4.0',
'Data Source="e:\share";User ID=Admin;Password=;Extended properties=dBase 5.0')...bmk
这样就可以把e:\share中的bmk.dbf表导入到Sqlserver中,
速度是最快的
把压箱底的方法都告诉大家
在Form上放一个ADOConnection,连结指向目标Access库
比如txt文件在c:\temp\aaaa.txt
就执行
ADOConnection.Connected := True;
ADOConnection.Execute('Select * Into abcd From [Text;Database=c:\temp].aaaa.txt');
就一切Ok了,这个方法一定行的,我好不容易才研究出来的
有了这两个例子,异构数据库之间导数据的问题就举一反三,迎刃而解了。把Excel导入到Access中,同txt类似
select * into <table name> from [excel 8.0;database=<filename>].[<sheetname>$]我最讨厌别人用BatchMove导数据了,明明一个SQL的事情,偏要
我的目标是让大家抛弃BatchMove
IORILI(眼镜@_@) ,
可以幫我在以下代碼中實現嗎unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, Excel2000, OleServer, BaseGrid, AdvGrid;type
TForm1 = class(TForm)
ExcelApplication1: TExcelApplication;
ExcelWorksheet1: TExcelWorksheet;
ExcelWorkbook1: TExcelWorkbook;
Button1: TButton;
OpenDialog1: TOpenDialog;
AdvStringGrid1: TAdvStringGrid;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var i,j:integer;
begin
opendialog1.InitialDir:=ExtractFileDir(paramstr(0));//文件的打存放初始路?
opendialog1.Execute;
Try
ExcelApplication1.Connect;//EXCEL?用程序
Except
MessageDlg('Excel may not be installed',mtError, [mbOk], 0);
Abort;
End;
ExcelApplication1.Visible[0]:=True;
ExcelApplication1.Caption:='Excel Application';
try
excelapplication1.Workbooks.Open(opendialog1.FileName,
null,null,null,null,null,null,null,null,null,null,null,null,0);except
begin
ExcelApplication1.Disconnect;//出?异常情????
ExcelApplication1.Quit;showmessage('???EXCEL?子表格!');
exit;
end;
end;
ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks[1]);
ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Worksheets[1] as _Worksheet);
for i:=1 to 1000 do//最大取值1000
for j:=1 to 6 do
begin
if trim(excelworksheet1.cells.item[i+1,1])<>'' then
begin
advstringgrid1.rowCount:=i+1;
advstringgrid1.Cells[j,i]:=ExcelWorksheet1.Cells.Item[i+1,j];
end
else
begin
ExcelApplication1.Disconnect;
ExcelApplication1.Quit;exit;
end;
end;
end;
end.
EXCEL 8.0不是指OFFICE97的嗎,我的是OFFICE2000,不會有問題嗎???
還有
SELECT * into bmk
FROM OpenDataSource( 'Microsoft.Jet.OLEDB.4.0',
'Data Source="e:\share";User ID=Admin;Password=;Extended properties=dBase 5.0')...bmk
這個SQL語句的OPENDATASOURCE怎麼來的.
if edit1.Text='' then
begin
showmessage('请选择部件价格BOM!');
exit;
end;
try begin screen.Cursor:=crHourGlass;
MyExcel:=createoleobject('Excel.Application');
MyWorkbook:=MyExcel.Workbooks.Open(datamodule2.OpenDialog1.FileName);
MyExcel.Visible:=false;
myworksheet1:=myexcel.worksheets[1];
end;
except
Application.Messagebox('Excel 没有安装!','ERROR!', MB_ICONERROR + mb_Ok);
Abort;
end;
ll_row:= myworksheet1.UsedRange.Rows.Count;
ll_col:=myworksheet1.UsedRange.columns.Count;
if ll_row<2 then
begin
if MessageDlg('当前EXCEL中没有数据!是否用此文件来清空以前的数据?',mtConfirmation,[mbYes, mbNo], 0)=mrNo then
begin
myworkbook.close;
myexcel.quit;
myexcel:=unassigned;
screen.Cursor := crdefault;
exit;
end ;
end;
//查找相应字段
for bom_comn:=1 to ll_col do
begin
if varastype(myworksheet1.cells.item[1,bom_comn],varstring)='专用号' then
type_field:=bom_comn;
if varastype(myworksheet1.cells.item[1,bom_comn],varstring)='单价' then
price_field:=bom_comn;
end;
if price_field<1 then
begin
messagebox(0,'所要导入的Excel表中没有单价,请重新选择!','警告!',0);
exit;
end;//导入数据
if ll_row>2 then
begin
for rr:=2 to ll_row do
try
begin
if (varastype(myworksheet1.cells[rr,type_field],varstring)<>'') then
begin
datamodule2.publicquery.Close;
datamodule2.publicquery.SQL.Clear;
datamodule2.publicquery.SQL.Add('execute import_price '''+varastype(myworksheet1.cells[rr,type_field],varstring)+''''+','''+varastype(myworksheet1.cells[rr,price_field],varstring)+''''+','''+h+'''');
datamodule2.publicquery.ExecSQL;
end;
end;
myworkbook.close;
myexcel.quit;
myexcel:=unassigned;
showmessage('数据导入成功!');
except
application.messagebox('无法完成!可能是数据格式不对,请检查后重新导入!','hello',mb_iconerror+mb_ok);
myworkbook.close;
myexcel.quit;
myexcel:=unassigned;