这样的文本文件如何读入数据库?(50分)

J

joann

Unregistered / Unconfirmed
GUEST, unregistred user!

尊敬的 郑一 先生/女士 :
我行已从您的帐户中支取以下金额作为本次供款额, 特此通知。
------------------------------------------------------------------------------
贷款帐号 : 400000000000000001 客户编号 : 00000001
楼盘名称 : xxxx建设发展有限公司 楼盘编号 : 000001
存款帐号 : 4000000000001234567  总期数 : 180
现用利率 : 0.00465000 罚息利率 : 0.00630000

期号 本金 利息 罚息 起息日期
------------------------------------------------------------------------------
20 4,670.04 5,185.98 0.00 2002-01-11

本次扣款金额为 : 9,856.02
阁下现时在我行的贷款余额为 : 1,110,594.20
------------------------------------------------------------------------------
说明:如有不符,请于扣款后20天内到经办 银行查询 ,过期则视阁下已认可。
...........
...........
...........
...........
...........
...........


尊敬的 王小一 先生/女士 :
我行已从您的帐户中支取以下金额作为本次供款额, 特此通知。
------------------------------------------------------------------------------
贷款帐号 : 400000000000000002 客户编号 : 00000007
楼盘名称 : xxxx建设发展有限公司 楼盘编号 : 000002
存款帐号 : 4000000000002222227  总期数 : 180
现用利率 : 0.00465000 罚息利率 : 0.00630000

期号 本金 利息 罚息 起息日期
------------------------------------------------------------------------------
3 407.72 1,420.40 1.00 2002-01-01

本次扣款金额为 : 1,828.12
阁下现时在我行的贷款余额为 : 337,781.94
------------------------------------------------------------------------------
说明:如有不符,请于扣款后20天内到经办 银行查询 ,过期则视阁下已认可。


读入PARADOX数据库表为
XM DKZH LPBH XYLL BJ LX FX RQ
郑一 400000000000000001 楼盘编号 : 000001 0.00465000 4,670.04 5,185.98 0.00 2002-01-01
...........
...........
...........
...........
...........
...........
王小一 400000000000000002 楼盘编号 : 000002 0.00465000 407.72 1,420.40 1.00 2002-01-01




这样的文本文件如何读入数据库?
 
只有一个一个的读,然后判断是不是你要的数据,是的话就存入数据库。
 
就当文件整个存进去
 
拷贝到excel,然后再导sqlserver
 
建议先读入一个TstringList控件中,然后按行进行相应的处理
如pos定位等。
 
格式化比较强的文本文件,应该比较好读。
 
自己写个程序一个一个的读吧。
 
同意sandsman的意见,用读文件的方式一行一行的读取,再拆解。存入不同的变量中,多个文件时,再加个循环
 
本人初学delphi,如何写?
 
下面是源代码:

unit Main;

interface

uses
Windows, Messages, SysUtils, Classes,
Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TForm1 = class(TForm)
Button2: TButton;
OpenDialog1: TOpenDialog;
Button1: TButton;
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button2Click(Sender:
TObject);
var
F: TextFile; {设定为文本文件}
StrLine: string; {every Line string}
SArray:array [0..500] of string; {String
array,由于可能不只500行,
因此最好定义为动态组......... }
line: Integer; {Text file's Line}
begin
if OpenDialog1.Execute then {Open file}
begin
AssignFile(F, OpenDialog1.FileName);
{Create file}
Reset(F);
Line:=0;
while not SeekEof(f) do {文件没有 eof}
begin
if SeekEoln(f) then {每一Line}
Readln;
Readln(F, StrLine);
SArray[Line]:=StrLine;
Caption:=StrLine; {I debug use it}
if Line<500 then {If >500 Line...}
inc(Line) else
Break;
end;
CloseFile(F); {Close file}
end;
end;

procedure TForm1.Button1Click(Sender:
TObject);
begin
Application.MessageBox('请你千万注意两个
问题:'+#13#10+
'1.有可能打开的文件远远不只500行
;'+#13#10+
'2.涉及到文件的操作时要注意I/O出错
'+#13#10+
'因此你务必提供相应的异常捕捉处理
.'+#13#10#13#10+
' 答一读者问 梁明1999-03',
'提示你
',MB_DefButton1+MB_IconInformation+MB_OK
);
end;

end.

窗体As text代码
object Form1: TForm1
Left = 192
Top = 107
Width = 279
Height = 168
Caption = '网易BBS朋友问--->梁明'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Button2: TButton
Left = 136
Top = 32
Width = 105
Height = 33
Caption = '读打开文件的行'
TabOrder = 0
OnClick = Button2Click
end
object Button1: TButton
Left = 136
Top = 77
Width = 105
Height = 33
Caption = '关于...'
TabOrder = 1
OnClick = Button1Click
end
object OpenDialog1: TOpenDialog
Filter = '文本文件(*.TXT)|*.TXT'
Title = '打开文本文件--->梁明'
Left = 48
Top = 32
end
end
 
用两个Stringlist,第一个s1先把文件load进来,
然后把s1中的":"replace成空格,用第二个Stringlist,
s2.commtext:=s1
贷款帐号->s2[1],客户编号->s2[3]
其他行,类似。


 
接受答案了.
 
顶部