用vb编写个管理软件数据库是excel的用adodc连接,并用DataGrid显示,但是数据库的内容比较多想分页显示,有大大说用top来可是top只能显示前n个,该怎么改,另外页数怎么获得并显示出来啊(就是比如100条数据10条一个,在列表下方出现1 2 3 4 5 6 7 8 9 10),这是数据库连接的东东。谢谢帮忙了
Private Sub Command1_Click()
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\soft\vb\excel\nw.xls;Mode=ReadWrite;Extended Properties=excel 8.0;Persist Security Info=False"
Adodc1.RecordSource = "select top 10 * from [nw1$] "
Adodc1.Refresh
'DataGrid1.RefreshEnd Sub

解决方案 »

  1.   

    不对啊,不懂你什么意思。DataGrid是一个表格控件,所有数据都可以加进去,如果太长会有滚动条,不会说显示不出来的啊。
      

  2.   

    Option  Explicit  Dim  conn  As  ADODB.Connection  Dim  lCurrentPage  As  Long    Private  Sub  cmdNext_Click()          lCurrentPage  =  lCurrentPage  +  1          Call  Loadcontrol(lCurrentPage)  End  Sub    Private  Sub  cmdPrevious_Click()          If  lCurrentPage  >  1  Then                  lCurrentPage  =  lCurrentPage  -  1                  Call  Loadcontrol(lCurrentPage)          End  If  End  Sub    Private  Sub  Form_Load()                    Set  conn  =  New  ADODB.Connection          conn.CursorLocation  =  adUseClient          conn.Open  "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data  Source="  &  App.Path  &  "\test2000.mdb;"            lCurrentPage  =  1          Call  Loadcontrol(lCurrentPage)    End  Sub  Private  Sub  Loadcontrol(lPage  As  Long)          Dim  adoPrimaryRS  As  ADODB.Recordset          Dim  lPageCount  As  Long          Dim  nPageSize  As  Integer          Dim  lCount  As  Long                    '每页显示的纪录          nPageSize  =  10          Set  adoPrimaryRS  =  New  ADODB.Recordset          adoPrimaryRS.Open  "select  *  from  numbers",  conn,  adOpenStatic,  adLockOptimistic            adoPrimaryRS.PageSize  =  nPageSize          '页数          lPageCount  =  adoPrimaryRS.PageCount          If  lCurrentPage  >  lPageCount  Then                  lCurrentPage  =  lPageCount          End  If                    adoPrimaryRS.AbsolutePage  =  lCurrentPage          '定义另一个记录集          Dim  objrs  As  New  ADODB.Recordset          '添加字段名称          For  lCount  =  0  To  adoPrimaryRS.Fields.Count  -  1                  objrs.Fields.Append  adoPrimaryRS.Fields(lCount).Name,  adVarChar,  adoPrimaryRS.Fields(lCount).DefinedSize          Next          '打开记录集          objrs.Open          '将指定记录数循环添加到objrs中          For  lCount  =  1  To  nPageSize  
             if not adoPrimaryRS.EOf then 
                    objrs.AddNew                  objrs!id  =  adoPrimaryRS!id                  objrs!anumber  =  adoPrimaryRS!anumber                  adoPrimaryRS.MoveNext  
              end if 
            Next          '绑定          Set  DataGrid1.DataSource  =  objrs                    '显示页数          txtPage  =  lPage  &  "/"  &  adoPrimaryRS.PageCount  End  Sub    Private  Sub  Form_Unload(Cancel  As  Integer)          If  Not  conn  Is  Nothing  Then                  conn.Close          End  If          Set  conn  =  Nothing  End  Sub