Results 1 to 3 of 3

Thread: Selection String still applied to Recordset

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2001
    Location
    Albany, NY
    Posts
    489

    Selection String still applied to Recordset

    2 programers have 2 different ways of opening recordsets.

    1st way - retrieve 1 record to Update
    VB Code:
    1. With DataEnvironment1.rstblLabs
    2.         If .State = adStateOpen Then .Close
    3.         .Open "SELECT * FROM tblLabs WHERE pkLab = " & p_pkLab, _
    4.                 , adOpenStatic, adLockOptimistic
    2nd way - retrieve all records to fill a combobox
    after the 1st way has already happened
    VB Code:
    1. With RS
    2.         If Not .State = adStateOpen Then
    3.             .Open , , adOpenStatic, adLockOptimistic
    When the second query to this table is executed the only
    record retrieved is the one from the 1st query. Is there any
    way to clear out the selection string from the 1st query and
    just retrieve all the records without passing a new selection
    string? This code is everywhere in the program so a major
    code change would be good to avoid.

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2001
    Location
    Albany, NY
    Posts
    489

    Maybe a better Question.....

    Is there a way (a property on the command object or the
    DataEnvironment) to force VB to query the Database and
    return all records on the .Open command if no selection
    string is specified????

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2001
    Location
    Albany, NY
    Posts
    489

    Is this a solid solution???

    Please view the comments in the code below:
    VB Code:
    1. 'I send a Selection String with this statement
    2. With DataEnvironment1.rstblHealthProfile
    3. .Open "SELECT * FROM tblHealthProfile WHERE 1 <> 1", , adOpenStatic, adLockOptimistic
    4.  
    5. ' The .Source property of the recordset now holds that selection
    6. ' string until another is issued. So the .Open method will send the
    7. ' same query next time it is executed. The statement below
    8. ' initialized the recordset (along with all other recordsets).
    9. Set DataEnvironment1 = Nothing
    10. ' Next time the recordset is opened the .Source is reset to
    11. ' select * from "dbo"."tblHealthProfile"
    Is this a solid solution?? Is this proper procedure and good coding
    to intialize the Dataenvironment like this??

    My co-workers say that it is the same as deallocating memory but
    I am under the impression that this is the same as setting an
    Integer value equal to 0. The solution works but are there any
    downfalls???

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