ADODB.Recordset AbsolutePage 不适用于 Oracle 数据库 (ASP.net)
我有以下代码:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
鉴于我对 ADODB 知之甚少,我的猜测是 ADODB 的 Oracle 提供程序不支持分页。
AbsolutePage
属性的文档 确实表明了这一点:因此,您可以在 Oracle 查询中进行分页,而不是在 ADO 和 VB.NET 中进行分页。
使用 Oracle 进行分页的典型方法是使用如下所示的查询。这将返回表
some_table
的第 31 到 40 行,这将是 10 行页面中的第 4 页:此查询中的两个数字应为
PageNum * ThePageSize
和(PageNum - 1) * ThePageSize
按此顺序。请注意,如果您尝试分页的查询具有
ORDER BY
子句或GROUP BY
子句,则需要将其移至另一个子查询中。例如,如果我们需要按列b
排序,然后对结果进行分页,我们会使用类似以下内容的内容: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: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: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 aGROUP BY
clause, you'll need to move that into another subquery. For example, if we needed to sort by columnb
and then page the results, we'd use something like: