I want to open up 2 record sets. Then, copy everything from one record
set to another (excluding a few fields). Is this possible?

I need to exclude my primary key, and fields starting with "TMP_".

I'm trying this, but it's saying ADODB.Recordset error '800a0c93'
Operation is not allowed in this context.



Public Function saveChanges()

Dim strSQL : strSQL = "SELECT * FROM imf WHERE imf_id = " & Form_id
Dim strSQLTMP : strSQLTMP = "SELECT * FROM imf WHERE TMP_imf_id
= " & Form_id
Dim rs : Set rs = Server.CreateObject("adodb.recordset")
Dim rsTMP : Set rsTMP = Server.CreateObject("adodb.recordset")
rs.CursorType = adOpenKeyset
rs.LockType = adLockOptimistic
rs.CursorLocation = adUseServer
rs.open strSQL,DBHandle.DBConn
rsTMP.open strSQL,DBHandle.DBConn

Dim i, strF
rs.movefirst
For i = 0 To rs.Fields.Count -1
echo i & "- " & rs.Fields(i).Name & "<br>"
strF = rs.Fields(i).Name
If strF = "imf_id" Then
' do nothing
echo "skipping " & strF & "<br>"
ElseIf Left(strF,3) = "TMP" Then
' do nothing
echo "tmpskipping " & strF & "<br>"
Else
rs.Fields.Item(i) = rsTMP.Fields.Item(i)
End If
Next

rs.close : rsTMP.close
Response.End

End Function

Re: easy way to (almost)copy a recordset. by Bob

Bob
Fri Jun 09 13:59:30 CDT 2006

Eric wrote:
> I want to open up 2 record sets. Then, copy everything from one record
> set to another (excluding a few fields). Is this possible?
>
> I need to exclude my primary key, and fields starting with "TMP_".
>


You really should stop using select *. I know you have a lot of fields, but
this is not the time to be lazy.
Wouldn't it be simpler (plus more efficient and les resource-intensive) to
simply return only the fields you want? It is wasteful of network bandwidth
and server resources to retrieve data you aren't going to use, simply
because you are too lazy to spell out the fields you want to retrieve.

You can create a view in the database that only return only the fields you
want, and simply select * from the view. No more cloning recordsets etc.

And again: you should not use a recordset to maintain data.

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"