为什么要在Delphi里面导呢
如果可能的话
调用MS SQL Server的DTS

解决方案 »

  1.   

    unit import;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, DB, ADODB;type
      TForm1 = class(TForm)
        Button1: TButton;
        OpenDialog1: TOpenDialog;
        Edit1: TEdit;
        Edit2: TEdit;
        Edit3: TEdit;
        ADOConnection1: TADOConnection;
        ADOQuery1: TADOQuery;
        DataSource1: TDataSource;
        Button2: TButton;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
       
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    var
        //filename:string;
        F: Textfile;
        S:string;
        sDate:string;
        sText:string;
        strsql:string;
    begin
        opendialog1.Title :='导入数据';
        opendialog1.Filter := 'Text files (*.txt)|*.TXT';
        if opendialog1.Execute then
            begin
                AssignFile(F, OpenDialog1.FileName);
                try
                    reset(F);
                    while not eof(f) do
                        begin
                             Readln(F, S);                        { Read first line of file }
                             if length(trim(s))<>0 then
                                 if pos('''',S)>0 then
                                    S:=stringReplace(S,'''','''''',[rfReplaceAll]);
                                 begin
                                    s:=trim(s);
                                    stext:=copy(s, 1, length(s)-10);
                                    sdate:=copy(s,length(s)-9,10) ;
                                    //showmessage(sdate);
                                    //Edit1.Text := S;
                                    strsql:='';
                                    //strsql:='insert into important(importantthing,importantdate) values( :stext ,:sdate)';
                                    strsql:=format('insert into important(importantthing,importantdate) values( ''%s'' ,''%s'')', [stext, sdate]);
                                    //strsql:='insert into important(importantthing,importantdate) values( ' + stext + ' ,'+ strtodate(sdate) + ')';
                                    adoquery1.Close;
                                    adoquery1.SQL.Clear ;
                                    adoquery1.SQL.Add(strsql);
                                    //AdoQuery1.Parameters.Items[0].Value := stext;
                                    //ADOQuery1.Parameters.Items[1].Value := strtodate(sdate);
                                    //showmessage(adoquery1.SQL.CommaText);
                                    try
                                         adoquery1.ExecSQL ;
                                    except
                                         showmessage('error');
                                    end;
                                 end;
                        end;
                finally                     { Put string in a TEdit control }
                    CloseFile(F);
                    //filename:=opendialog1.filename ;
                    //showmessage(F);
                end;
                showmessage('ok');
            end;
    end;procedure TForm1.Button2Click(Sender: TObject);
    begin   if Pos('''', edit2.Text ) > 0 then
        showmessage('haha');
        edit2.Text :=stringreplace(edit2.Text,'''','''''',[rfReplaceAll]);end;end.