Discussion:
Modifying fields and Adding new rows to Disconnected RecordSet
(too old to reply)
Ron
2004-03-04 18:36:09 UTC
Permalink
I am using VB6 to create and navigate (using .Find) disconnected (ADO) recordsets. This works great. I now want to modify some fields in an existing row (rs.field = "Some Data") and/or add new rows (rs.addnew). I have researched this through various forums and find snipets about setting various properties (.CursorLocation, .CursorType, .LockType, etc), but somehow cannot get the right combination to make this happen. Error = "Current recordset does not support updating...". Is there a cookbook or complete code snipet out there to help me. Thanks...Ron
T***@NOSPAM.earthlink.net
2004-03-05 02:53:58 UTC
Permalink
Post by Ron
am using VB6 to create and navigate (using .Find) disconnected (ADO)
recordsets. This works great. I now want to modify some fields in an
existing row (rs.field = "Some Data") and/or add new rows (rs.addnew). I
have researched this through various forums and find snipets about
setting various properties (.CursorLocation, .CursorType, .LockType,
etc), but somehow cannot get the right combination to make this happen.
Error = "Current recordset does not support updating...". Is there a
cookbook or complete code snipet out there to help me. Thanks...Ron
The correct way to work with disconnected recordsets is to.......

Use a Client side cursor location.

Open using adlockbatchOptimistic as the locktype.

After open set the recordset.Activeconnection = nothing before you close the
connection.

Use the normal .Addnew method to add records to the recordset.
Just modify fields of existing records.
Use .update to commit changes in the local recordset for either add or edit.

when ready to send the changes back to the database, set the
ActiveConnection of the Recordset back to a valid, open ADO connnection
object.

Use the .updateBatch method to commit all the changes back.
--
Robert Berman
Vulcan Software Services
***@NOSPAM.earthlink.net
Ron
2004-03-05 18:51:06 UTC
Permalink
Hi Robert, Thanks for your reply. I tried your comments with no success, but used your leads and came up with the "RecSetName.CursorType = adOpenKeyset" addition to the code. Still No Joy. The only difference between the examples I've seen and my code is that I move the recordset created from the Database into another recordset for VB manipulation. Below are the debug messages I get when running the code. My code follows the messages

?RecSetName.Supports (adAddNew
Fals

?erro
Current Recordset does not support updating. This may be a limitation of the provider, or of the selected locktype

Thanks again...Ro

Private Sub Form_Load(
Dim RecSetName As ADODB.Recordse

Set RecSetName = New ADODB.Recordse
RecSetName.LockType = adLockBatchOptimisti
RecSetName.CursorLocation = adUseClien
RecSetName.CursorType = adOpenKeyse
sSql = "SELECT DISTINCTROW ExpDate, Field1, Field2, ' ' AS StatDescr FROM Table1
If GetData(RecSetName, sSql, "") The
Do Until RecSetName.EO
If U.DBLng(RecSetName!ExpDate) < nAdvMemExpDate
Then RecSetName!StatDescr = " [EXPIRED]"
Else RecSetName!StatDescr = " [Active]
'Error occurs on the above IF statemen
..
End Su

Public Function GetData(rsO As Object,
sSql As String,
sParam As String,
Optional nRows As Long = 0) As Boolea
On Error GoTo ErrorTa
Dim rs As ADODB.Recordse
Dim nRetryCt As Intege

nRetryCt =
GetData = Fals
nRows =
Set rs = New ADODB.Recordse
sSql = sSql & sPara

ReTryTag
If ConnectDB() The
TheDB.Execute sSq
rs.CursorLocation = adUseClien
rs.Open sSql, TheDB, adOpenForwardOnly, adLockReadOnly, adCmdTex
Set rs.ActiveConnection = Nothin
If Not rs.EOF The
rs.MoveLas
rs.MoveFirs
GetData = (rs.RecordCount > 0
nRows = rs.RecordCoun
End I
Set rsO = r
End I

ExitTag
Set rs = Nothin
Exit Functio

ErrorTag
..
End Functio
Val Mazur
2004-03-06 03:55:10 UTC
Permalink
Hi Ron,

It depends on how you opened your recordset. Even if you specify client-side
cursor for your settings, does not mean that provider will do this. I think
you are using Execute method of ADO connection or command object to open
recordset. In this case, by-default, recordset will be opened on a server
side as a read-only, forward-only. Could you post your code here we could
see what it does?
--
Val Mazur
Microsoft MVP
Post by Ron
I am using VB6 to create and navigate (using .Find) disconnected (ADO)
recordsets. This works great. I now want to modify some fields in an
existing row (rs.field = "Some Data") and/or add new rows (rs.addnew). I
have researched this through various forums and find snipets about setting
various properties (.CursorLocation, .CursorType, .LockType, etc), but
somehow cannot get the right combination to make this happen. Error =
"Current recordset does not support updating...". Is there a cookbook or
complete code snipet out there to help me. Thanks...Ron
Ron
2004-03-06 18:36:06 UTC
Permalink
Hi Val, I did just that probably when you were replying. See Above.

Thanks...Ron
Ron
2004-03-06 18:56:05 UTC
Permalink
Hi Val (again). I read your reply re: copying recordsets vs "cloning' them. On further debugging of my code, I found the VB recordset uses the properties of the DB recordset regardless of what I set the VB recordset properties. I do not want to change the properties of the DB recordset as I believe this is the fastest retrieval method and I do not update the database for recordsets. Am I in fact cloning the DB recordset (thereby overiding properties) and will copying the recordset solve the problem

Ron
Ron with success (I think)
2004-03-07 22:46:05 UTC
Permalink
Thanks All (both those who replied and other users of this service

I moved from what I believe was a cloned Recordset to a copied one using XML. I believe this is a good move because
1) It works an
2) It positions me to keep my legacy recordsets (which I love) yet allow me to migrate to the ADO.NET when I am ready or circumstances dictate I must

Thanks again...Ron

Loading...