zoukankan      html  css  js  c++  java
  • 用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;


     

  • 相关阅读:
    第三百八十二节,Django+Xadmin打造上线标准的在线教育平台—xadmin管理员详情页面布局,导航图标设置
    THINKPHP5近期暴露的漏洞
    同事孩子满月酒送诗十二首
    东莞电台送诗
    前两天解决了一个贴吧里面牛年找牛的问题
    群友作诗大会
    老系统维护有感
    家和万事兴 歌词
    傻大个的保健人生遭遇
    东莞电台忽来关心,寥寥数语,余有感言
  • 原文地址:https://www.cnblogs.com/smallmuda/p/1312366.html
Copyright © 2011-2022 走看看