title: Copy records to another recordset using Active Server Page
body: <p>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).</p>
  
  <p>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:</p>
  
  <p><pre><code>
  Set rsTemp = CopyRecordsetStructure(objRs)
  rsTemp.Open
  iRecordsShown = 0
  Set objFields = objRs.Fields
  intFieldsCount = objFields.Count-1 
  Do While iRecordsShown &lt; 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</p>
  
  <p>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
  </pre></code></p>
  
  <p>The issue is i could not open the" rsTemp". It throws me error</p>
  
  <p><pre><code>
  The connection cannot be used to perform this operation. It is either closed or invalid in this context.
  </pre></code></p>
  
  <p>If I use some dummy query and connection it doesn't work.</p>
  
  <p>Please help to copy the records from one recordset to another new record set.</p>
  
  <p>Thanks in advance
  Ganesh.</p>