我目前面临一个从文本文件中读取数据到sql数据库中的问题(100分)

D

dxh2002

Unregistered / Unconfirmed
GUEST, unregistred user!
[?]我目前面临一个从文本文件中读取数据到sql数据库中的问题:
1、每隔5秒发送一次数据
2、文本文件格式:
aa1 bb cc 1999-02-01 dd 5
aa2 bb cc 1999-02-01 dd 5
aa3 bb cc 1999-02-01 dd 5
aa4 bb cc 1999-02-01 dd 5
3、数据库中的字段:char,char,char,datetime,char,integer
4、如何能准确的读取某一行、某一列数据
5、程序为服务性质,起动之后,不在桌面上显示,但要在任务栏右下角显示一个小图标,
双击之后,显示一管理窗口,可以结束该任务

 
如何能准确的读取某一行、某一列数据,谁能回答?
 
var
f:textfile;
s1:string[20];
s2:string[20];
s3:string[20];
s4:string[20];
s5:string[20];
begin
打开表;
assignfile(f,"文本文件名“);
reset(f);
try
while not eof(f) do
readln(f,s1,s2,s3,s4,s5);
table.open;
table(s1):=s1;
......自己写吧
table.post;
  end;
finally
closefile(f);
end;
 
procedure TForm1.Button7Click(Sender: TObject);
var
TextFileVar: Textfile;
fileN: string;
a, b, c, dd,d,e,temp: string;
n:integer;
begin
if opendialog1.execute then
begin
FileN := opendialog1.FileName;
if FileN = '' then Exit;
AssignFile(TextFileVar, FileN);
Reset(TextFileVar);
table1.open;
table1.edit;
while not SeekEof(TextFileVar) do
begin
Readln(TextFileVar, temp);
a := copy(temp, 1, pos(' ', temp) - 1);
temp := copy(temp, pos(' ', temp) + 2, length(temp) - pos(' ', temp));
b := copy(temp, 1, pos(' ', temp) - 1);
temp := copy(temp, pos(' ', temp) + 1, length(temp) - pos(' ', temp));
c := copy(temp, 1, pos(' ', temp) - 1);
temp := copy(temp, pos(' ', temp) + 1, length(temp) - pos(' ', temp));
dd := copy(temp, 1, pos(' ', temp) - 1);
temp := copy(temp, pos(' ', temp) + 2, length(temp) - pos(' ', temp));
d := copy(temp, 1, pos(' ', temp) - 1);
e:= copy(temp, pos(' ', temp) + 1, length(temp) - pos(' ', temp));
table1.append;
table1.fields[0].AsString := a;
table1.fields[1].AsString := b;
table1.fields[2].AsString := c;
table1.fields[3].AsString := dd;
table1.fields[4].AsString := d;
table1.fields[5].AsInteger := StrToInt(trim(e));
end;
table1.post;
closeFile(TextFileVar);
end;
end;
 
1,每隔几秒发送数据可以用TIMER来控制
2,从文本读取数据楼上两位老兄的都可以
3,这样的读取在每次读取完成后,得将原来的数据删除,否则会出现越来越多的重复数据
4,读取某一行或某一列的数据在文本中可没有听过,这得到数据库文件里来查了
5,加到任务,可以API函数了.
 
补充一点:
我的文本文件每两个数据之间不是用空格来分隔的,而是用tab,不知该怎样拆分,好象
pos(' ', temp)不可以
readln(f,s1,s2,s3,s4,s5);把第一行所有数据都读到了s1中,s2,s3,s4,s5都为空,不知怎
为什么,好像以空格分隔也是一样,
我用的是d6+补丁2,不知你们用的是什么版本,不过应该不会与版本有关
 
我给你的源码是根据你给的数据格式编写的
>>文本文件每两个数据之间不是用空格来分隔的,而是用tab
一般用空格或“,”,用tab是把,把空格换为tab即可,道理是一样的。
Readln(TextFileVar, temp);
解析temp。
 
I'm wrong ;mdc是正确的,但用tab分隔,该怎样拆分,请告知
 
将‘ ’处均改为char(9)--9为tab的键值
 
多人接受答案了。
 
顶部