在将ACCESS数据填入到stringgrid表格中时出现如上提示ADOQuery2.Close;
   ADOQuery2.SQL.Clear;
   ADOQuery2.SQL.Text:='select 编码,名称,规格,单位,单价,数量,金额,性质 from smxdl where 编号='''+DBgrid1.Fields[11].AsString+'''';
   ADOQuery2.Open;   if ADOQuery2.RecordCount >0 then
    Groupbox6.Enabled:=true;
    stringgridcreat;
    with   ADoQuery2   do
     begin
     StringGrid1.RowCount:=ADoQuery2.RecordCount;
     StringGrid1.ColCount:=ADoQuery2.Fields.Count;
     ppt:=1;
     while not Eof do
      begin
      for ttp:=1 to StringGrid1.ColCount-1 do
       stringgrid1.Cells[0,ttp]:=inttostr(ttp);
       StringGrid1.Cells[ttp,ppt]:=Fields[ttp].AsString;
       Inc(ppt);
       ADoQuery2.Next;
      end;
     end;
代码如上

解决方案 »

  1.   

         StringGrid1.RowCount:=ADoQuery2.RecordCount +1;
         StringGrid1.ColCount:=ADoQuery2.Fields.Count +1;
    都 多加1 再试试嘛
      

  2.   

    ttp:=1 to StringGrid1.ColCount-1
    这里的-1不要,刚好8个
      

  3.   

      ...
      while not Eof do
      begin
        for ttp:=1 to StringGrid1.ColCount-1 do
        begin
          stringgrid1.Cells[0,ppt]:=inttostr(ppt);            //序号替代编码,不显示编码
          StringGrid1.Cells[ttp,ppt]:=Fields[ttp].AsString;   //显示编码后数据
        end;
        Inc(ppt);
        Next;
      end;
      

  4.   

    楼主 注意检查代码啊  
    你整个for语句循环体都写错了  我楼上也正解