我有一个Txt文件,格式如:
68859102032000000314,马贵元,2000/09/20,10.33,632121196308124514,,
68859102032000000569,马孝福,2001/03/02,208.71,632801196403080516, ,
68859102032000000619,马麻乃,2001/03/23,270.19,622923195101155313,13892259441,
里面有很多行这样的数据,我想把把导入到mdb中的表db,DB表字段有
帐号,姓名,日期,卡号,手机号
写入到表中后窗口上的DBGRID要能显示帐号,姓名,日期,卡号,手机号
日期这一列写到表的日期字段中格式为20000920这样的,把/去掉
高人急救啊,如何写代码,导入按钮的代码如何弄?读入TXT文件时以逗号分隔符
68859102032000000314,马贵元,2000/09/20,10.33,632121196308124514,,
68859102032000000569,马孝福,2001/03/02,208.71,632801196403080516, ,
68859102032000000619,马麻乃,2001/03/23,270.19,622923195101155313,13892259441,
里面有很多行这样的数据,我想把把导入到mdb中的表db,DB表字段有
帐号,姓名,日期,卡号,手机号
写入到表中后窗口上的DBGRID要能显示帐号,姓名,日期,卡号,手机号
日期这一列写到表的日期字段中格式为20000920这样的,把/去掉
高人急救啊,如何写代码,导入按钮的代码如何弄?读入TXT文件时以逗号分隔符
成功后打开表,关联显示到dbgrid
TextFileVar: Textfile ;
fileN,s: string;
ckr,zh,kh,sfz,grade,temp:string; num:integer;
begin
num:=0;
if opendialog1.execute then
begin
FileN:=opendialog1.FileName;
If FileN='|' Then
Exit;
AssignFile ( TextFileVar , FileN ) ;
Reset(TextFileVar);
memo1.Lines.LoadFromFile(opendialog1.FileName);
if messagedlg('确定要将该文本导入数据库吗?',mtconfirmation,[mbyes,mbno],0)=mryes then
begin
while not SeekEof(TextFileVar) do
begin
Readln ( TextFileVar , temp ) ;
if pos(',',temp)>0 then begin
zh:=copy(temp, 1, pos(',',temp)-1);
temp:=copy(temp,pos(',',temp)+1,length(temp)-pos(',',temp));
ckr:=copy(temp, 1, pos(',',temp)-1);
temp:=copy(temp,pos(',',temp)+1,length(temp)-pos(',',temp));
kh:=copy(temp, 1, pos(',',temp)-1);
temp:=copy(temp,pos(',',temp)+1,length(temp)-pos(',',temp));
sfz:=copy(temp, 1, pos(',',temp)+1);
temp:=copy(temp,pos(',',temp)+1,length(temp)-pos(',',temp)); adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from sj');
adoquery1.Open;
if adoquery1.RecordCount=0 then
begin
adotable1.Open;
adotable1.insert;
adotable1.fields[7].AsString:=zh;
adotable1.fields[0].AsString:=ckr; adotable1.Fields[9].AsString:=kh;
adotable1.Fields[5].AsString:=sfz;
adotable1.post;
end
else
num:=num+1;
adoquery1.Close;
s:=inttostr(num);
end;
end;
showmessage('有'+s+'条记录相同而未导入数据库');
closeFile(TextFileVar);
adotable1.Close;
showmessage('有效文件成功导入数据库');
end;
end;
end;这段代码我能写入zh(帐号)ckr(存款人)kh(开户日期),但sfz(身份证)只能读能出68859102032000000314,马贵元,2000/09/20,10.33,632121196308124514,,
这段中的10.33,怎样才能读出632121196308124514呢?
temp:=copy(temp,pos(',',temp)+1,length(temp)-pos(',',temp));
ckr:=copy(temp, 1, pos(',',temp)-1);
temp:=copy(temp,pos(',',temp)+1,length(temp)-pos(',',temp));
kh:=copy(temp, 1, pos(',',temp)-1);
temp:=copy(temp,pos(',',temp)+1,length(temp)-pos(',',temp));
temp:=copy(temp,pos(',',temp)+1,length(temp)-pos(',',temp));//直接取10.33后面的字符串
sfz:=copy(temp, 1, pos(',',temp)+1);
temp:=copy(temp,pos(',',temp)+1,length(temp)-pos(',',temp));
kh:=stringreplace(kh,'/','',[rfReplaceAll]);//这个函数应该是strutils里的,需要引用。