将文本中带格式的数据导入到数据库中

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"> 
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;
  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"> 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值