Results 1 to 12 of 12

Thread: [RESOLVED] why I can update the recordset?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2008
    Posts
    255

    Resolved [RESOLVED] why I can update the recordset?

    Dear all,

    Following is my code. I want to know why I can still update the recordset and the result is reflected in the database even I am using adOpenForwardOnly? Thanks

    Code:
    aStrsql = " select ...from ... where ..."
    
    If fn_SqlOpenRS(aRs, aStrsql, adCmdText, gConnect_Main, adUseServer, adOpenForwardOnly) Then
        i = 0
        While Not aRs.EOF
            ' do some calculation..
            aRs!s_totalAmount = aRs!r_totalAmount             
            ..
            aRs!s_last_update_time = Now
            aRs!s_remark = "SW_frmMassUpdate -> f_confirm_Redem -> From Corresponding Redemption"
    
            aRs.Update
            i = i + 1
            aRs.MoveNext
        Wend
        Call fn_closeADOrs(aRs)
    Else
          MsgBox ("Error in opening the query."), vbCritical, gProjectName_SW
    End If
    I can still live in my current job because I am here

  2. #2
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,957

    Re: why I can update the recordset?

    Forward Only has nothing to do with whether or not a recordset is updatable. All it means is that you can only work your way forward through it. So this:-
    Code:
    aRs.MoveLast
    whould not work. This performs better than a two way recordset but has the obvious limitations that you can't go backwards.
    The best argument against democracy is a five minute conversation with the average voter - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

  3. #3
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: why I can update the recordset?

    Try using adLockReadOnly
    Last edited by Pradeep1210; Apr 30th, 2009 at 07:59 AM.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  4. #4
    Hyperactive Member Max Peck's Avatar
    Join Date
    Oct 2007
    Posts
    384

    Re: why I can update the recordset?

    Quote Originally Posted by Pradeep1210 View Post
    Try using adLockReadOnly
    Why would you do that? He's trying to update the recordset.

    -Max
    The name's "Peck" .... "Max Peck"

    "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." - Red Adair

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Sep 2008
    Posts
    255

    Re: why I can update the recordset?

    thanks all.
    My question is: Can adOpenForwardOnly perform aRs.update?
    I can still live in my current job because I am here

  6. #6
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,957

    Re: why I can update the recordset?

    Yes. It can.
    The best argument against democracy is a five minute conversation with the average voter - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Sep 2008
    Posts
    255

    Re: why I can update the recordset?

    Quote Originally Posted by FunkyDexter View Post
    Yes. It can.
    Why? Then.. i am confused..
    What I think in my mind is that... adOpenForwardOnly only allow "READ" the recordset, but not allow update...

    Is this concept totally wrong???????


    Then, what is AdOpenKeySet??

    Sorry.. I really get confused..
    I can still live in my current job because I am here

  8. #8
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,957

    Re: why I can update the recordset?

    Is this concept totally wrong
    I afraid so.

    I think you've completely missunderstood the purspose of adOpenForwardOnly . It's nothing to do with whether or not the recordset is read only. The only affect it has is that it means you can't work backwards through the rescordset. Because it doesn't need to support working backwards it's 'lighter'. By that I mean that it uses less memory and will perform quicker. Most of the time, when you open a recordet, you'll want to start at the beginning and work forward until you reach the end. If that's what you're doing then it makes sense to use adOpenForwardOnly because it'll be a bit quicker and you're not losing anything because you don't want to work backwards anyway.

    There are quite a few different qualifiers you can choose between when opening a recordset and they behave in different ways in combination. This site gives quite a nice simplistic view. For a more complete analysis you could check MSDN.
    The best argument against democracy is a five minute conversation with the average voter - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

  9. #9
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: why I can update the recordset?

    Think of adOpenForwardOnly as a one-way street.... but I can still go into shops on the street and purchase items....but, I cannot go back to previous shops - it's a one-way street.

    adOpenKeyset is a two-way street... allowing me to go forward and backwards up and down the street & visiting any shop along the way.

    It's possible to have adOpenForwardOnly & adLockReadOnly .... all the shops on the one-way street are closed ... all I can do is look in through the windows.

    It's also possible to adOpenKeyset & adLockReadOnly ... all the shops on the two way street are closed... all I can do is look in through the windows.

    Does that help?

    =tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  10. #10
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: why I can update the recordset?

    It's probably worth taking a look at the FAQ article What do the parameters of the recordset.Open method mean?, as it gives explanations of adOpenForwardOnly/adLockReadOnly/etc.

  11. #11
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: why I can update the recordset?

    adOpenForwardOnly is a CursorType, not a LockType, so it won't prevent one from an updating a recordset.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Sep 2008
    Posts
    255

    Re: why I can update the recordset?

    Quote Originally Posted by techgnome View Post
    Think of adOpenForwardOnly as a one-way street.... but I can still go into shops on the street and purchase items....but, I cannot go back to previous shops - it's a one-way street.

    adOpenKeyset is a two-way street... allowing me to go forward and backwards up and down the street & visiting any shop along the way.

    It's possible to have adOpenForwardOnly & adLockReadOnly .... all the shops on the one-way street are closed ... all I can do is look in through the windows.

    It's also possible to adOpenKeyset & adLockReadOnly ... all the shops on the two way street are closed... all I can do is look in through the windows.

    Does that help?

    =tg
    a good example. Get it. thanks
    I can still live in my current job because I am here

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width