ADODB.Recordset AbsolutePage 不适用于 Oracle 数据库 (ASP.net)

发布于 2024-11-28 11:54:02 字数 876 浏览 1 评论 0原文

我有以下代码:

Dim PageNum AS Integer = 1
Dim ThePageSize As Integer = 30
Dim RowCT As Integer = 0

Dim SqlStr As String = "SELECT * FROM TheTable"
Dim TCConStr As String = ConfigurationManager.ConnectionStrings("TCConStr").ConnectionString

Dim Objrs As New ADODB.Recordset

Objrs.Open(SqlStr, TCConStr, 3, 3)

If Not Objrs.EOF Then
  Objrs.MoveFirst()
  Objrs.PageSize = ThePageSize
  Dim TotalPages As Integer = Objrs.PageCount
  Objrs.AbsolutePage = PageNum
End If

While Not Objrs.EOF And RowCT < Objrs.PageSize
  RowCT = RowCT + 1

  'Do Stuff

  Objrs.MoveNext()
End While
Objrs.Close()
Objrs = Nothing

当我尝试运行它时,我得到: “System.Runtime.InteropServices.COMException:当前记录集不支持书签。这可能是提供程序或所选光标类型的限制。” 错误页面指向“Objrs.AbsolutePage = PageNum”

如果我在这里做错了什么,或者我可以采取什么措施来解决它,有什么想法吗?在一页上显示 500 条记录确实有点糟糕。

I have the following code:

Dim PageNum AS Integer = 1
Dim ThePageSize As Integer = 30
Dim RowCT As Integer = 0

Dim SqlStr As String = "SELECT * FROM TheTable"
Dim TCConStr As String = ConfigurationManager.ConnectionStrings("TCConStr").ConnectionString

Dim Objrs As New ADODB.Recordset

Objrs.Open(SqlStr, TCConStr, 3, 3)

If Not Objrs.EOF Then
  Objrs.MoveFirst()
  Objrs.PageSize = ThePageSize
  Dim TotalPages As Integer = Objrs.PageCount
  Objrs.AbsolutePage = PageNum
End If

While Not Objrs.EOF And RowCT < Objrs.PageSize
  RowCT = RowCT + 1

  'Do Stuff

  Objrs.MoveNext()
End While
Objrs.Close()
Objrs = Nothing

When I try to run it I get:
"System.Runtime.InteropServices.COMException: Current Recordset does not support bookmarks. This may be a limitation of the provider or of the selected cursortype."
The error page points to "Objrs.AbsolutePage = PageNum"

Any ideas of if I have done anything wrong here, or what I can do to get around it? It would kind of really stink to show 500 records on one page.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浪荡不羁 2024-12-05 11:54:03

鉴于我对 ADODB 知之甚少,我的猜测是 ADODB 的 Oracle 提供程序不支持分页。 AbsolutePage 属性的文档 确实表明了这一点:

提供者必须支持适当的功能才能使该属性可用。

因此,您可以在 Oracle 查询中进行分页,而不是在 ADO 和 VB.NET 中进行分页。

使用 Oracle 进行分页的典型方法是使用如下所示的查询。这将返回表 some_table 的第 31 到 40 行,这将是 10 行页面中的第 4 页:

SELECT a, b, c
  FROM (SELECT a, b, c, ROWNUM as num
          FROM some_table
         WHERE ROWNUM <= 40)
 WHERE num > 30

此查询中的两个数字应为 PageNum * ThePageSize(PageNum - 1) * ThePageSize 按此顺序。

请注意,如果您尝试分页的查询具有 ORDER BY 子句或 GROUP BY 子句,则需要将其移至另一个子查询中。例如,如果我们需要按列 b 排序,然后对结果进行分页,我们会使用类似以下内容的内容:

SELECT a, b, c
  FROM (SELECT a, b, c, ROWNUM as num
          FROM (SELECT a, b, c 
                  FROM some_table
                 ORDER BY b)
         WHERE ROWNUM <= 40)
 WHERE num > 30

My somewhat naïve guess, given that I know very little about ADODB, is that the Oracle provider for ADODB doesn't support paging. The documentation for the AbsolutePage property does indeed suggest this:

The provider must support the appropriate functionality for this property to be available.

So, instead of doing the paging in your ADO and VB.NET, you could do the paging in your Oracle query.

The typical way of doing paging with Oracle is to use a query like the following. This returns the 31st to the 40th rows of the table some_table, which would be for the 4th page of 10-row pages:

SELECT a, b, c
  FROM (SELECT a, b, c, ROWNUM as num
          FROM some_table
         WHERE ROWNUM <= 40)
 WHERE num > 30

The two numbers in this query should be PageNum * ThePageSize and (PageNum - 1) * ThePageSize in that order.

Note that if the query you're attempting to page has an ORDER BY clause or a GROUP BY clause, you'll need to move that into another subquery. For example, if we needed to sort by column b and then page the results, we'd use something like:

SELECT a, b, c
  FROM (SELECT a, b, c, ROWNUM as num
          FROM (SELECT a, b, c 
                  FROM some_table
                 ORDER BY b)
         WHERE ROWNUM <= 40)
 WHERE num > 30
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文