例用AdoQuery+ListView分页

Delphi 专栏收录该内容
3 篇文章 0 订阅

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, ADODB,Grids, DBGrids, StdCtrls, ComCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    ADOConnection1: TADOConnection;
    ADOQuery1: TADOQuery;
    ListView1: TListView;
    Label1: TLabel;
    Button2: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
    procedure Page_Count;
  public
    { Public declarations }
  end;
var
  Form1: TForm1;
  page: integer;
implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
  ListItem:TListItem;
  i:integer;
begin
  with AdoConnection1 do
  begin
    ConnectionString := '连接串';
    open();
  end;
  Page := 0;
end;

procedure TForm1.Page_Count;
var
  i:integer;
  ListItem:TListItem;
begin
  ListView1.Clear;
  with AdoQuery1 do
  begin
    Connection := AdoConnection1;
    sql.Clear;
    sql.Add('select a,b from tmplive');
    open;
    if Page = 0 then Page := 1;
    if Page > RecordSet.RecordCount then page := RecordSet.RecordCount;
    Recordset.PageSize := 10;
    RecordSet.AbsolutePage := Page;
    for i:= 1 to Recordset.PageSize do
    begin
      ListItem := ListView1.Items.Add;
      ListItem.SubItems.Add(RecordSet.Fields.Item[0].value);
      ListItem.SubItems.Add(RecordSet.Fields.Item[1].Value);
      Next;
      if RecordSet.EOF then exit;
    end;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Page := Page+1;
  Page_Count;
  Label1.Caption := IntToStr(Page);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
    Page := Page -1;
    Page_Count;
    Label1.Caption := IntToStr(Page);
end;

end.

  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值