为什么总是少一条记录?

nnnnyyyy 2004-12-28 09:07:35
用ADOConnection ADOTable 链接Excel。分别用了DBGrid和StringGrid。
在DBGrid中的记录数是正确的,用StringGrid却总是少最后一条记录.

//导入数据到StringGrid
colcount := fromADOTable.Fields.Count;//得到数据集中的字段数与记录数
rowcount := fromADOTable.RecordCount;

fromProgressBar.Max := rowcount;//进度条的初始化
fromProgressBar.Position := 0;

fromStringGrid.ColCount := colcount+1; //调整StringGrid行、列数。列数增加一行,以便确定是否导入
fromStringGrid.RowCount := rowcount;

fromStringGrid.Cells[0,0] := '序';
fromStringGrid.Cells[1,0] := '是否导入';

Lbcolandrow.Caption := '数据源中共有'+InttoStr(colcount)+'个字段和'+ InttoStr(rowcount)+'条记录!';

for row := 0 to rowcount-1 do
begin
fromStringGrid.Cells[1,row+1] := '是'; //用户确定是否导入
fromStringGrid.Cells[0,row+1] := InttoStr(row+1); //每条记录作标记,既第一列排序
for col := 0 to colcount-1 do
begin
if fromADOTable.Fields[col].Value <> null then//如果记录不会空,则赋值
begin
fromStringGrid.Cells[col+2,row+1] := fromADOTable.Fields[col].Value;
end;
end;

if not fromADOTable.Eof then //如果不是最后一条记录,则指针下移
begin
fromADOTable.Next;
fromProgressBar.Position := row;
end;
end;
ShowMessage('共执行了:'+InttoStr(number));
...全文
118 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
peterluolaw 2004-12-28
  • 打赏
  • 举报
回复
删除下面的试试
if not fromADOTable.Eof then //如果不是最后一条记录,则指针下移
begin
fromADOTable.Next;
fromProgressBar.Position := row;
end;
JonnySun 2004-12-28
  • 打赏
  • 举报
回复
支持 pinyu(品雨) !
Kevin_Lmx 2004-12-28
  • 打赏
  • 举报
回复
for row := 0 to rowcount-1 do
->
for row := 0 to rowcount do
pinyu 2004-12-28
  • 打赏
  • 举报
回复
fromStringGrid.RowCount := rowcount;应该是RowCount+1
因为你前面还有个表头。所以应该是记录数+表头。
@原野 2004-12-28
  • 打赏
  • 举报
回复
这么快全回答了,同意一二楼

2,497

社区成员

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

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