使用 Active Server Page 将记录复制到另一个记录集
我正在使用经典 ASP 进行编程。我正在尝试进行分页。我的后端是 SQL CE 3.5。不幸的是,它不支持 SQL 查询中的分页(如 sql server 中的 row_number() )。
所以我选择 ASP 分页。但是当我询问记录集时,通过设置 rs.PageSize 和 rs.AbsolutePage 等给我前 10 条记录,它给我所有记录。因此,我计划仅将结果记录集中的前 10 行复制到另一个新记录集。所以我编码如下:
Set rsTemp = CopyRecordsetStructure(objRs)
rsTemp.Open
iRecordsShown = 0
Set objFields = objRs.Fields
intFieldsCount = objFields.Count-1
Do While iRecordsShown < intPageSize And Not objRs.EOF
rsTemp.AddNew
For Idx = 0 To intFieldsCount
rsTemp.Fields(Idx).Value = objRs.Fields(Idx).Value
Next
rsTemp.Update
iRecordsShown = iRecordsShown + 1
objRs.MoveNext
Loop
公共函数 CopyRecordsetStructure(ByVal rs)
调暗温度
设置 rsTemp = CreateObject("ADODB.Recordset")
设置 objFields = rsTemp.Fields
intFieldCount = objFields.Count - 1
对于 Idx = 0 至 intFieldCount
rsTemp.Fields.Append objFields(Idx).Name, _
objFields(Idx).Type, _
objFields(Idx).DefinedSize
下一个
设置 CopyRecordsetStructure = rsTemp
结束功能
问题是我无法打开“rsTemp”。它会抛出错误
The connection cannot be used to perform this operation. It is either closed or invalid in this context.
如果我使用一些虚拟查询和连接它就不起作用。
请帮助将记录从一个记录集复制到另一个新记录集。
提前致谢 加内什。
I'm programming in Classic ASP. I'm trying to do the paging. My backend is SQL CE 3.5. Unfortunetly, it doesn't support paging in SQL Query (Like row_number() in sql server).
So I go with ASP Paging. But when i ask to the recordset, give me the first 10 records by setting the rs.PageSize and rs.AbsolutePage and all, it gives me all records. So I planned to copy only first 10 rows from the resultant recordset to another new recordset. So I coded like below:
Set rsTemp = CopyRecordsetStructure(objRs)
rsTemp.Open
iRecordsShown = 0
Set objFields = objRs.Fields
intFieldsCount = objFields.Count-1
Do While iRecordsShown < intPageSize And Not objRs.EOF
rsTemp.AddNew
For Idx = 0 To intFieldsCount
rsTemp.Fields(Idx).Value = objRs.Fields(Idx).Value
Next
rsTemp.Update
iRecordsShown = iRecordsShown + 1
objRs.MoveNext
Loop
Public Function CopyRecordsetStructure(ByVal rs) Dim rsTemp Set rsTemp = CreateObject("ADODB.Recordset") Set objFields = rsTemp.Fields intFieldCount = objFields.Count - 1 For Idx = 0 To intFieldCount rsTemp.Fields.Append objFields(Idx).Name, _ objFields(Idx).Type, _ objFields(Idx).DefinedSize Next Set CopyRecordsetStructure = rsTemp End Function
The issue is i could not open the" rsTemp". It throws me error
The connection cannot be used to perform this operation. It is either closed or invalid in this context.
If I use some dummy query and connection it doesn't work.
Please help to copy the records from one recordset to another new record set.
Thanks in advance
Ganesh.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不确定,但这看起来不对,
不是吗?
Not sure, but this looks wrong
Shouldn't it be
根据以上注释中的注释和修复,该函数应更新为:Set objFields = rs.Fields 为:
用法:
更新代码
With the comments and fixed in the above comments, the function should be updated Set objFields = rs.Fields to:
Usage:
Update Code