一边是access数据库,一边是sql server数据库,如何把access中的内容导入sql server(100分)

  • 主题发起人 主题发起人 iwantflywithwin
  • 开始时间 开始时间
I

iwantflywithwin

Unregistered / Unconfirmed
GUEST, unregistred user!
一边是access数据库,一边是sql server数据库,如何把access中的内容导入sql server
,不是手工导啊,用delphi在程序中实现。急!!!!
 
用SELECT---- INTO ----有用,查一下书.
delphi的datapump也可以!
 
用控件batchmove,很好用的
 
sql 有导入数据功能。
 
如果表结构一样的话就可以用batchmove来处理了,否则就只能用query取出来再插入另外一个里面
 
使用
MSSQL7/Binn/dtswiz.exe
 
procedure TFormMain.ChangeDataClick(Sender: TObject);
var
FileName: String;
ConStr: WideString;
SqlStr: String;
i: Integer;
BB: Boolean;
upDate: TDateTime;
//StringList: TStringList;
begin
Screen.Cursor := crHourGlass;
BB := False;
if OpenDialog1.Execute then
begin
FileName := OpenDialog1.FileName;
if length(ExtractFileName(FileName)) = 11 then
begin
upDate := FileDateToDateTime(FileAge(FileName));
ConStr := 'Provider=Microsoft.Jet.OLEDB.4.0;';
ConStr := ConStr + 'Data Source=' + FileName + ';';
ConStr := ConStr + 'Persist Security Info=False';
ADOConnection1.Close;
ADOConnection1.ConnectionString := ConStr;
ADOConnection1.Open;
SqlStr := 'SELECT sTime, sDate, sWho FROM ADB WHERE (sWhere = ''电子门2,门外'') ORDER BY sDate, sWho';
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add(SqlStr);
ADOQuery1.Open;
//StringList := TStringList.Create;
//StringList.LoadFromFile(SetupFile);
SQLUser := 'cwa_login';
SQLPass := 'cwa';
SQLIP := '192.168.161.201';
//SQLIP := StringList[0];
//SQLUser := StringList[1];
//SQLPass := StringList[2];
//StringList.Free;
ConStr := 'Provider=SQLOLEDB.1;';
ConStr := ConStr + 'Password=' + SQLPass + ';';
ConStr := ConStr + 'Persist Security Info=True;';
ConStr := ConStr + 'User ID=' + SQLUser + ';';
ConStr := ConStr + 'Data Source=' + SQLIP;
ADOConnection2.Close;
ADOConnection2.ConnectionString := ConStr;
ADOConnection2.Open;
{for i := 0 to ADOTable1.RecordCount - 1 do
begin
if ADOTable1.FieldByName('sDate').AsString = ADOQuery1.FieldByName('sDate').AsString then
BB := True;
ADOTable1.Next;
end;}
{ADOTable2.Open;
if ADOTable2.IsEmpty = False then
begin
for i := 0 to ADOTable2.RecordCount - 1 do
begin
if ADOTable2.FieldByName('date').AsString = ADOQuery1.FieldByName('sDate').AsString then
BB := True;
ADOTable1.Next;
end;
end;}
ADOTable2.Open;
if ADOTable2.IsEmpty = False then
begin
for i := 0 to ADOTable2.RecordCount - 1 do
begin
if ADOTable2.FieldByName('file').AsString = ExtractFileName(FileName) then
BB := True;
ADOTable2.Next;
end;
end;

if BB = True then
ShowMessage('数据已加入')
else
begin
if ADOQuery1.RecordCount > 0 then
begin
ADOTable1.Open;
for i := 0 to ADOQuery1.RecordCount - 1 do
begin
ADOTable1.Append;
ADOTable1.FieldByName('sDate').AsString :=
ADOQuery1.FieldByName('sDate').AsString;
ADOTable1.FieldByName('sTime').AsString :=
ADOQuery1.FieldByName('sTime').AsString;
ADOTable1.FieldByName('sWho').AsString :=
ADOQuery1.FieldByName('sWho').AsString;
ADOQuery1.Next;
end;
ADOTable1.Post;
ADOTable2.Append;
ADOTable2.FieldByName('file').AsString := ExtractFileName(FileName);
ADOTable2.FieldByName('upDate').AsDateTime := upDate;
ADOTable2.Post;
end;
ShowMessage('数据加入成功');
end;
ADOQuery1.Close;
ADOTable2.Close;
end
else
ShowMessage('文件选择错误');
ADOTable1.Close;
ADOConnection1.Close;
end;
Screen.Cursor := crDefault;
end;
 
KOKS
请问备份恢复的启动是哪一个??谢谢!
老人家
你的结果我要测试一下,然后就可以给你分数了,谢谢
 
多人接受答案了。
 
后退
顶部