如何利用Delphi调用写字本的文字并写入数据库的相应字段(200分)

  • 主题发起人 主题发起人 KDMYDREAM
  • 开始时间 开始时间
K

KDMYDREAM

Unregistered / Unconfirmed
GUEST, unregistred user!
比如写字本名: hanzi.txt
写字本的内容是:
1 一马当先 aaa
2 四季如春 bbb
3 你好 cvc
数据库(SQLServer)表hanzi字段有:NO(整型),HZ(字符型),HZBM(字符型)
现在的问题是:将1,2,3送入NO字段中,一马当先,四季如春,你好送入HZ字段中,
aaa,bbb,ccc送入字段cvc中。
主要是扫描写字本的一行,当遇到一个空格,空格前面的文字,是一个字段的内容,
比如上面有两个空格,并能实现所用写字本的数据送入数据库!不知如何实现。望告知。
 
procedure TForm1.Button1Click(Sender: TObject);
var
TextFileVar: Textfile ;
fileN: string;
id, hz,bm,temp: string;
begin
FileN:='hanzi.txt';
AssignFile ( TextFileVar , FileN ) ;
Reset(TextFileVar);
table1.open;
table1.edit;
while not SeekEof(TextFileVar) do
begin
Readln ( TextFileVar , temp ) ;
id:=copy(temp, 1, pos(' ',temp)-1);
temp:=copy(temp,pos(' ',temp)+1,length(temp)-pos(' ',temp));
hz:=copy(temp,1,8);
bm:=copy(temp, 10,length(temp)-9);
table1.append;
table1.fields[0].AsInteger:=StrToInt(id);
table1.fields[1].AsString:=hz;
table1.fields[2].AsString:=bm;
end;
table1.post;
closeFile(TextFileVar);
end;
 
现在有问题了!第一行写入数据库是对的,但是第二行,第三行就不对了!出现的结果是:
no hz hzbm
1 一马当先 aaa
2 四季如春bbb
3 你好cvc
hzbm从的二行就是空白
 
linsb
调试错误的原因主要是中间的汉字不一定是是四个!它是不定的!
所以你用8是错误,能否给出正确的程序,我可以再给你100分。
 
to KDMYDREAM
我按你给我的文件格式编的,你的意思是不是各字段间用空格分隔?
 
写字本名: hanzi.txt
写字本的内容是:
1 一马当先 aaa
2 四季如春 bbb
3 你好 cvc

....
id:=copy(temp, 1, pos(' ',temp)-1);
temp:=copy(temp,pos(' ',temp)+1,length(temp)-pos(' ',temp));
hz:=copy(temp, 1, pos(' ',temp)-1);
bm:=copy(temp,pos(' ',temp)+1,length(temp)-pos(' ',temp));
.....
 
对是用空格分开的!
 
你好,问题解决了!
我全部给你!
我们可以经常向你请教,我得qq:4526112
 
接受答案了.
 
后退
顶部