• 用AdoQuery分页 实例



    今晚在csdn论坛上看到一个网友在问分页,就随便写了一段代码,如有不当之处,还请见谅。

    首先在窗体上放个listview,两个button,一个label,一个adoquery,一个adoconnection
    然后用adoconnection建立一个连接

    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.

    -----------------------------------ADOquery循环

    var
      Lv_Count : Integer;
    begin
    Lv_Count := 0;
    if not adoQuery1.isEmpty then
    begin
      adoQuery1.First;
      while not adoQuery1.eof do
      begin
        Lv_Count := Lv_Count + 1;
        adoQuery1.next;
      end;
    end;
    end;


     

  • 相关阅读:
    程序员式的幽默(灌水)
    你应该知道的
    WPF控件应用[0]
    WPF控件应用[2]
    C#调用Win32 的API函数User32.dll
    C#获取当前行号
    C#导入excel重写
    [转]wpf相关好资源
    使用C#和Excel进行报表开发-生成统计图Chart
    [转]用 delphi 创建一个服务程序
  • 原文地址:https://www.cnblogs.com/smallmuda/p/1312366.html
Copyright © 2020-2023  润新知