CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: rs.open or not

  1. #1
    Join Date
    May 2001
    Posts
    91

    rs.open or not

    Hi out there,

    How can I check if a recordset is open or closed? If I unload a form usually a recordset is still open, but on one occation it's closed.
    The recordset is not nothing then.
    Anybody got an Idea?

    have a nice day,

    Patzer
    have a nice day

    Patzer
    _____________________________
    Philo will never be forgotten

  2. #2
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: rs.open or not

    For ADO, you can use the next code

    If rst.state = adStateClosed then
    Msgbox "Recordset is closed"
    else
    Msgbox "Recordset is open"
    End If




    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  3. #3
    Join Date
    May 2001
    Posts
    91

    Re: rs.open or not

    thanx a lot!!!

    simple when you know how (as always in VB).


    have a nice day,

    Patzer
    have a nice day

    Patzer
    _____________________________
    Philo will never be forgotten

  4. #4
    Join Date
    Aug 2001
    Posts
    26

    Re: rs.open or not

    you can use the state property of the recordset if the recordset is open the rs.state value will be 1 and if the recordset is closed the rs.state value will be 0.this will help you to determine whether the recordset is open or closed.



  5. #5

    Re: rs.open or not

    no.. it' not correct...

    rs.state=0 then rs is closed...
    bur rs.state=1 is not a correct test...
    an rs can be in adStateOpen and adStateFetching ...so its state is 9...

    the correct test is
    'with reference
    if rs.state and adstateopen then
    'so i'm sure rs is open
    end if

    'without reference
    if rs.state and 1 then
    'so i'm sure rs is open
    end if

    hi,brt


    <center>
    <HR width=80%>
    <img src='http://web.tiscali.it/bertaplanet/im...ertaplanet.gif'>
    </center>

  6. #6
    Join Date
    May 2001
    Posts
    91

    Re: rs.open or not

    Hi,
    I have to admit that I do not really understand your idea so:
    If a recordset.state returns true for adStateFetching at a time, does it also return true for adStateOpen at that time?
    I mean there are also other states for the rs, as of adstateconnecting and adstateexecuting, so could you please give a little more Information on that?

    thx´

    have a nice day,

    Patzer
    have a nice day

    Patzer
    _____________________________
    Philo will never be forgotten

  7. #7

    Re: rs.open or not

    the rs.state is a sum of state...

    adStateClosed = 0 'bynary ->0000
    adStateOpen = 1 'bynary ->0001
    adStateConnecting = 2 'bynary ->0010
    adStateExecuting = 4 '0100
    adStateFetching = 8 '1000

    if U want tio check state U must have a bynary check rs.state AND constant -> but it is a bad test when rs.state=adstateopen

    so if (rs.state and adstateopen)=false then rs is closed...

    exaple rs.state=adstateopen+adstateexecuting
    so rs.state=5 -> 0101...

    hi,btr

    <center>
    <HR width=80%>
    <img src='http://web.tiscali.it/bertaplanet/im...ertaplanet.gif'>
    </center>

  8. #8
    Join Date
    May 2001
    Posts
    91

    Re: rs.open or not

    Hi Berta,

    thx, took some time but then I understood (I think I did :-))



    have a nice day,

    Patzer
    have a nice day

    Patzer
    _____________________________
    Philo will never be forgotten

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

Featured