We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Making read-only recordset updatable

StuckInTheMud
on
Medium Priority
420 Views
Last Modified: 2013-12-25
Hi,

I'm looking for a way to change a read-only recordset into an updateable one.

The application queries several tables and, due to the links, returns a non-updateable result.

I then disconnect this (ActiveConnection=Null) and want to edit the results for a report, but I can't see a way of changing the results table.

I've tried saving it as a persisted recordset and reopening as editable, but it still remembers that it cannot be updated.

Anyone any clues?


Thanks!


Jim
Comment
Watch Question

leclairm.Net Developer  ERP integration

Commented:
Are these updates temporary???

If not, why not do the updates directly on the table that needs to be updated using the connection object
yourconn.execute "update table set yourfield = NewData where tablekey = " & localrs.fields("key")

then set the local recordsets connection back and refresh it.



Author

Commented:
Yes, they are temporary for the report. I specifically don't want to change underlying data.


Jim
leclairm.Net Developer  ERP integration

Commented:
Why would you like to only "temporarily" change the data??

What db is this?  Access??  You could always look into using temporary tables turn the queries into insert statements and then modify the temp tables and run your reports off of these tables.  Although this isn't very "clean".

Perhaps you could make the changes in the query itself??  If these are calculations, that would be quite easy to do.

Author

Commented:
DB is Oracle and SQL Server (I have a couple of apps I want to do this in).

I'm using the recordset as a grid for a report that is displayed/exported to excel. The changes are things like removing specific text for display grouping.

Anyway, this is irrelevant to the original query, how to make a read-only recordset into an editable one.
leclairm.Net Developer  ERP integration

Commented:
Try using a disconnected recordset:

Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
conn.Open ""Provider=sqloledb;Data Source=YourServer;Initial Catalog=YourDb;User Id=;Password=;"
rs.CursorLocation = adUseClient
rs.LockType = adLockBatchOptimistic
rs.Open "SELECT Table1.Test, Table2.test1 FROM Table1 JOIN table2 ON Table1.Pkey = Table2.Pkey;", conn
Set rs.ActiveConnection = Nothing
rs.fields(1) = "Mike "

I opened the above and it's originally not updatable, but once it was disconnected, I was able to make modifications.
leclairm.Net Developer  ERP integration

Commented:
Okay I just re-read your original question and you already tried a disconnected recordset?!?!

Perhaps your locktype was wrong??
>how to make a read-only recordset into an editable one.

You can not.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Commented:
if u wan to edit data,then do not open ur recordset as read-only...
really simple logic and concept...
have fun...
make a copy of the original recordset using

  Set rs2 = CopyRecordset(rs)

rs2 will be updateable.

Public Function CopyRecordset(ByRef rs As Recordset) As Recordset
    Dim fld As ADODB.Field
    Dim rsDummy As New Recordset ' the resulting recordset
   
    ' create fields in rsDummy
    For Each fld In rs.Fields
        rsDummy.Fields.Append fld.Name, fld.Type, fld.DefinedSize, fld.Attributes
    Next
   
    rsDummy.Open
   
    ' copy the recordset's content
    While Not rs.EOF
        rsDummy.AddNew
        For Each fld In rs.Fields
            rsDummy.Fields(fld.Name) = rs.Fields(fld.Name)
        Next
        rsDummy.Update
        rs.MoveNext
    Wend
   
    Set CopyRecordset = rsDummy
    Exit Function
End Function
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.