我想把table1中某一字段所有数据拷贝到table2中的指定字段下,这段程序应该怎样实现。谢谢大家。

解决方案 »

  1.   

    table1.first;
    while not table1.eof do
    begin
      table2.append;
      table2.fieldbyname('字段名').asstring:=table1.fieldbyname('字段名').asstring;
      table2.post;
    end;
      

  2.   

    补充上面,忘记写
    table1.Next
      

  3.   

    table2.FieldValues['字段名1'] := table1.FieldValues['字段名2'];
      

  4.   

    看清楚一点题目(或者是楼主没表达清楚),楼主只是要拷贝某一个字段的所有值,而并不要求每次都在table2里面新增(append)记录,要实现这样的程序,首先要你的数据库表设计要有相关的设计考虑,就是说table1和table2要有关联字段,对于table2的一行记录的指定字段,只拷贝table1中符合条件的某一行记录的指定字段的值。
      假设table1通过table2_id字段和table2的id字段进行关联,可以这样写:
    table2.First;
    while (table2.Eof = False) do
    begin
      table1.First;
      if (table1.Locate('table2_id', table2.FieldValues['id'], []) = True) then
        table2.FieldValues['destination_field'] := table1.FieldValues['source_field'];
      table2.Next;
    end;
      

  5.   

    还是 hthunter(核桃) 说的有道理,支持~!