使用 Active Server Page 将记录复制到另一个记录集

发布于 2024-10-02 01:24:47 字数 1259 浏览 3 评论 0原文

我正在使用经典 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 技术交流群。

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

发布评论

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

评论(2

极度宠爱 2024-10-09 01:24:47

不确定,但这看起来不对,

Set objFields = rsTemp.Fields

不是吗?

Set objFields = rs.Fields

Not sure, but this looks wrong

Set objFields = rsTemp.Fields

Shouldn't it be

Set objFields = rs.Fields
晨曦慕雪 2024-10-09 01:24:47

根据以上注释中的注释和修复,该函数应更新为:Set objFields = rs.Fields 为:

用法:

Dim rsTemp
Set rsTemp = CopyRecordset(rsPadicon)

更新代码

Public Function CopyRecordset(rs)

    Dim rsTemp, objFields, intFieldsCount, intPageSize
    Set rsTemp = CopyRecordsetStructure(rs)
    rsTemp.Open

    Set objFields = rs.Fields
    intFieldsCount = objFields.Count-1 

    response.write("<li> rs.RecordCount  :" & rs.RecordCount  & "</li>")
    ' response.write("<li> intFieldsCount  :" & intFieldsCount & "</li>")

    rs.MoveFirst 
    Do While Not rs.EOF
        rsTemp.AddNew

        Dim i
        For i = 0 to intFieldsCount 'use i as a counter
            ' response.write("<li> Name :" & rs.Fields(i).Name & "</li>")
            ' response.write("<li> Value :" & rs.Fields(i).Value & "</li>")
            if Not IsNull(rs.Fields(i).Value) then 
                rsTemp.Fields(i).Value = rs.Fields(i).Value
            End if
        Next

        rsTemp.Update

        rs.MoveNext
    Loop

    Set CopyRecordset = rsTemp


End Function


Public Function CopyRecordsetStructure(ByVal rs)
     Dim rsTemp, objFields, intFieldCount, Idx
     Set rsTemp = CreateObject("ADODB.Recordset")
     Set objFields = rs.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

With the comments and fixed in the above comments, the function should be updated Set objFields = rs.Fields to:

Usage:

Dim rsTemp
Set rsTemp = CopyRecordset(rsPadicon)

Update Code

Public Function CopyRecordset(rs)

    Dim rsTemp, objFields, intFieldsCount, intPageSize
    Set rsTemp = CopyRecordsetStructure(rs)
    rsTemp.Open

    Set objFields = rs.Fields
    intFieldsCount = objFields.Count-1 

    response.write("<li> rs.RecordCount  :" & rs.RecordCount  & "</li>")
    ' response.write("<li> intFieldsCount  :" & intFieldsCount & "</li>")

    rs.MoveFirst 
    Do While Not rs.EOF
        rsTemp.AddNew

        Dim i
        For i = 0 to intFieldsCount 'use i as a counter
            ' response.write("<li> Name :" & rs.Fields(i).Name & "</li>")
            ' response.write("<li> Value :" & rs.Fields(i).Value & "</li>")
            if Not IsNull(rs.Fields(i).Value) then 
                rsTemp.Fields(i).Value = rs.Fields(i).Value
            End if
        Next

        rsTemp.Update

        rs.MoveNext
    Loop

    Set CopyRecordset = rsTemp


End Function


Public Function CopyRecordsetStructure(ByVal rs)
     Dim rsTemp, objFields, intFieldCount, Idx
     Set rsTemp = CreateObject("ADODB.Recordset")
     Set objFields = rs.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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文