为什么最后一个字符串不能插入到表中?

jacky_hou 2005-04-12 07:01:17
一个文本文件是这样的
王小栓
张大中
要将他们插入到ACCESS表中,但是用我下面的程序就只能插入王小栓,而不能插入张大中,请问为什么?

unit Unit1;

interface

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

type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
//===================access
SecConstr:wideString;
SecCnn:TADOConnection;
SecDataSet:TADODataSet;
implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
SecConStr:='Provider=Microsoft.Jet.OLEDB.4.0;Password="";Data Source=' + ExtractFilePath(Application.ExeName) + '\TEST.mdb;Persist Security Info=True';
SecCnn:=TADOConnection.Create(nil);
SecCnn.LoginPrompt:=false;
SecDataSet:=TADODataSet.Create(nil);
//打开access连接
Seccnn.ConnectionString:=SecConstr;
SecCnn.Open;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
F: TextFile;
ID: String[8];
Name: String[8];
begin

//有问题的地方
SecDataSet.Connection:=SecCnn;
SecDataSet.CommandText:='select * from hou';
SecDataSet.Open;
AssignFile(F,'table.txt');
Reset(F);
while not Eof(F) do
begin
Readln(F,NAME);
SecDataSet.Append;
SecDataset.Fields[1].AsString:=Name;
end;
CloseFile(F);
end;
end.
...全文
47 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
real_name 2005-04-12
  • 打赏
  • 举报
回复
//有问题的地方
SecDataSet.Connection:=SecCnn;
SecDataSet.CommandText:='select * from hou';
SecDataSet.Open;
AssignFile(F,'table.txt');
Reset(F);
while not Eof(F) do
begin
Readln(F,NAME);
SecDataSet.Append;
SecDataset.Fields[1].AsString:=Name;
//////这要 post 啊
end;
CloseFile(F);
end;
end.

2,497

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧