with DataModule1.Q do
    begin
    sql.Clear;
    SQL.Add('select *  from "temp.db"');
   while not eof do
    begin
       with listview1.Items.Add do
        begin
        caption:=FieldByName('编码').AsString ;
        subitems.add(FieldByName('菜名').AsString);
        subitems.add(FieldByName('单位').AsString);
        subitems.add(FieldByName('单价').AsString);
        end;
      next;
    end;
    open;
end; 
这样写可是listview没有东东

解决方案 »

  1.   

    with DataModule1.Q do
        begin
        sql.Clear;
        SQL.Add('select *  from "temp.db"');
        open;  
       while not eof do
        begin
           with listview1.Items.Add do
            begin
            caption:=FieldByName('编码').AsString ;
            subitems.add(FieldByName('菜名').AsString);
            subitems.add(FieldByName('单位').AsString);
            subitems.add(FieldByName('单价').AsString);
            end;
          next;
        end;
        
    end; 
      

  2.   

    同意楼上说的,先open 才能操作
      

  3.   

    如果是作为一个独立过程的话最好要在添加之前先将listview中的东东给清除了,^_^
      

  4.   

    建议写成如下代码;
    with DataModule1.Q do
        begin
        if active then close;
        sql.Clear;
        SQL.Add('select *  from "temp.db"');
        open;
        listview1.clear;
       while not eof do
        begin
           with listview1.Items.Add do
            begin
            caption:=FieldByName('编码').AsString ;
            subitems.add(FieldByName('菜名').AsString);
            subitems.add(FieldByName('单位').AsString);
            subitems.add(FieldByName('单价').AsString);
            end;
          next;
        end;
    end;