用StringGrid代替DBGrid来显示数据表中的数据,请问stringgrid怎么加入数据的?有例子吗?

解决方案 »

  1.   

    循环将一个字段一个字段加进去就得了StringGrid1.Cells[i,j]:=table1.field(0).value
      

  2.   

    StringGrid1.Cells[i,j]中的i代表列数,j代表行数while not table1.eof do
    begin
      j:=0;
      for i:=0 to m   //m=你的数据库字段数-1
        StringGrid1.Cells[i,j]:=table1.field(i).value  //获得第一条记录的各字段值
      j:=j+1;
      Tale1.Next;
    end;
      

  3.   

    while not table1.eof do
    begin
      j:=0;
      for i:=0 to 2 //m=你的数据库字段数-1
        StringGrid1.Cells[i,j]:=table1.fields[i].value  //获得第一条记录的各字段值
      j:=j+1;
      Tale1.Next;
    end;
    仅录入最后一条记录
      

  4.   

    j:=0;
    while not table1.eof do
    begin  
      for i:=0 to 2 //m=你的数据库字段数-1
        StringGrid1.Cells[i,j]:=table1.fields[i].value  //获得第一条记录的各字段值
      j:=j+1;
      Tale1.Next;
    end;
      

  5.   

    table1.First;
    j:=0;
    while not table1.eof do
    begin  
      for i:=0 to 2 //m=你的数据库字段数-1
        StringGrid1.Cells[i,j]:=table1.fields[i].value;  //获得第一条记录的各字段值
      j:=j+1;
      Tale1.Next;
    end;
      

  6.   

    循环前要把指向第一条记录,所以在我的代码前加Table1.first;
    另,现在没有直接把数据文件直接导入StringGrid的控件,因此只有采用这种逐条导入的办法。
      

  7.   

    To: yuwu_zjl() 
    执行后出错
    "Could not convert variant of type (Null) into type (String)"
      

  8.   

    to lanxingw(Qao Kei) 
    table.field中有空数据造成
    "Could not convert variant of type (Null) into type (String)".
    怎么办??