將文本中帶格式的數據導入到數據庫中

<iframe name="google_ads_frame" marginwidth="0" marginheight="0" src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-3528650120430763&dt=1183890684015&lmt=1183890684&format=468x60_as&output=html&correlator=1183890684000&url=http%3A%2F%2Fgmai9999.googlepages.com%2Fhome&ad_type=text_image&ui=rc%3A0&cc=100&flash=9&u_h=768&u_w=1024&u_ah=738&u_aw=1024&u_cd=32&u_tz=480&u_java=true" frameborder="0" width="468" scrolling="no" height="60" allowtransparency="allowtransparency"></iframe> 
procedure TFmMain.BtngoClick(Sender: TObject);
var
  txtfile : TextFile;
  txtstr,tmpstr  : string;
  id,Num,L_ID,U_ID,U_Name : string;
  s : integer;
begin
  //連接數據庫
  con.Connected := false;
  con.KeepConnection := true;
  con.Connected := true;
  dataset.Active := false;
  dataset.CommandText := 'select * from txttable ';
  try
     dataset.Open;
  except
     dataset.Active := false;
  end;
  //讀取文本文件
  txtstr := trim(EText.Text);
  if fileexists(txtstr) then
  begin
     AssignFile(txtfile,txtstr);
     Reset(txtfile);
     while not eof(txtfile) do
     begin
        ReadLn(txtfile,tmpstr);

        //從文本中取得字段數據
             s := Pos(',',tmpstr);
             id := copy(tmpstr,1,s-1); //
             delete(tmpstr,1,s);
             s := Pos(',',tmpstr);
             U_ID := copy(tmpstr,1,s-1); //
             delete(tmpstr,1,s);
             s := Pos(',',tmpstr);
             U_Name := copy(tmpstr,1,s-1); //
             delete(tmpstr,1,s);
             s := Pos(',',tmpstr);
             Num := copy(tmpstr,1,s-1); //
             delete(tmpstr,1,s);
             s := Pos(',',tmpstr);
             L_ID := copy(tmpstr,1,s-1); //
             delete(tmpstr,1,s);

        //寫入數據庫
             with DataSet do
             begin
                DataSet.Append;
                FieldByName(ID').AsString  := id;
                FieldByName('U_ID').AsString := U_ID;
                FieldByName('U_Name').AsString := U_Name;
                FieldByName(Num').AsString := Num;
                FieldByName('L_ID').AsString := L_ID ;
                Post;
             end;    // with

     end;    // while
  end;
  showmessage('導入數據庫完畢');
end;
 <iframe name="google_ads_frame" marginwidth="0" marginheight="0" src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-3528650120430763&dt=1183890684015&lmt=1183890684&format=468x60_as&output=html&correlator=1183890684000&url=http%3A%2F%2Fgmai9999.googlepages.com%2Fhome&ad_type=text_image&ui=rc%3A0&cc=100&flash=9&u_h=768&u_w=1024&u_ah=738&u_aw=1024&u_cd=32&u_tz=480&u_java=true" frameborder="0" width="468" scrolling="no" height="60" allowtransparency="allowtransparency"></iframe> 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章