老总交代任务,把文本导入SQL,我写了个简易的工具 可是每次只能导入第一行,望各位大虾指教一下 谢谢了!procedure TForm1.Button1Click(Sender: TObject);
var
str:string;
TxtFile:TextFile; //定义文本变量
ch:Char;
begin
with adoquery1 do //打开数据库
adoquery1.Close;
adoquery1.SQL.Add('select * from jzgdzcxx');
adoquery1.open;
assignfile (txtfile,'d:/1.txt'); //将文本分配给变量
reset(txtfile); //打开文本变量
str:='';
while not eof(txtfile) do //只要文本没有结束 就循环转换
begin
readln (txtfile,ch); //从文本读第一个字符
if ch<>char(13) then //判断是否为回车
str:=str+ch //不是回车 继续读下一个
else
begin
table1.Active:=true; //是回车 表明读完一行 此时str为一行记录
table1.Append;
table1.Edit;
table1.fieldbyname('编号').AsString:=copy(str,1,12);
table1.FieldByName('日期').AsString:=copy(str,14,4)+'/'+copy(str,18,2)+'/'+copy(str,20,2);
table1.FieldByName('数据').AsString:=copy(str,23,16);
table1.Post;
readln (txtfile,ch);
str:='';
next;
end;
end;
end;另外 加了个清空按钮 点击后 再导入,连一行都导入不了了···procedure TForm1.Button2Click(Sender: TObject);
begin
with adoquery1 do
close;
adoquery1.sql.add('delete from jzgdzcxx');
adoquery1.ExecSQL;
end;
end.
var
str:string;
TxtFile:TextFile; //定义文本变量
ch:Char;
begin
with adoquery1 do //打开数据库
adoquery1.Close;
adoquery1.SQL.Add('select * from jzgdzcxx');
adoquery1.open;
assignfile (txtfile,'d:/1.txt'); //将文本分配给变量
reset(txtfile); //打开文本变量
str:='';
while not eof(txtfile) do //只要文本没有结束 就循环转换
begin
readln (txtfile,ch); //从文本读第一个字符
if ch<>char(13) then //判断是否为回车
str:=str+ch //不是回车 继续读下一个
else
begin
table1.Active:=true; //是回车 表明读完一行 此时str为一行记录
table1.Append;
table1.Edit;
table1.fieldbyname('编号').AsString:=copy(str,1,12);
table1.FieldByName('日期').AsString:=copy(str,14,4)+'/'+copy(str,18,2)+'/'+copy(str,20,2);
table1.FieldByName('数据').AsString:=copy(str,23,16);
table1.Post;
readln (txtfile,ch);
str:='';
next;
end;
end;
end;另外 加了个清空按钮 点击后 再导入,连一行都导入不了了···procedure TForm1.Button2Click(Sender: TObject);
begin
with adoquery1 do
close;
adoquery1.sql.add('delete from jzgdzcxx');
adoquery1.ExecSQL;
end;
end.
解决方案 »
- 哪位高人研究过水晶报表啊?
- 小弟以前曾经看过一个用delphi写的内存释放的程序,不知哪位大哥可以给个提示!!!
- 急!在三层中有时用ApplyUpdates(0)提交服务器会报错,不知为什么?
- 请zhoutian618(周天)进来拿分,关于reportbuilder
- 关于查询字段怎么都显示不完全?
- 解决了一个大问题,高兴!散分。
- 一个select的句子(高分)
- 求教一个位置转换API函数?
- 各位高手,我只需要有20个客户端同时使用一个程序来对服务器的数据库信息进行单据录入,修改等,该用两层还是三层的技术啊?
- 怎么样把一张表的数据根据相应的字段更新回五张其他表里???
- delphi自带的indy demo 无法正确下载邮件,大小总是-1,并且附件总是第一次打开的邮件的附件。
- 窗体多层调用的困惑
最后一行读不出来!
而且SQL数据库里的记录是任意排列的 不是按读的顺序排列