Results 1 to 7 of 7

Thread: [RESOLVED] Need to be clarified

  1. #1

    Thread Starter
    PowerPoster Simply Me's Avatar
    Join Date
    Aug 2003
    Posts
    2,748

    Resolved [RESOLVED] Need to be clarified

    Hi! I need to be clarified with some issues.

    when to Use:
    1.
    Code:
    If rs.State = adStateOpen Then rs.Close
    rs.Open sSQL, oConn, adOpenDynamic, adLockOptimistic
    and
    Code:
    oConn.Execute
    Questions:
    1. Which is recommended from the two?
    2. Is it always necessary to do this everytime I use sSQL = "SELECT * FROM TABLE"?
    Code:
    If rs.State = adStateOpen Then rs.Close
    rs.Open sSQL, oConn, adOpenDynamic, adLockOptimistic
    3. Which is recommeded, declare Dim rs As ADODB.Recordset in declaration area and Set to nothing every unload of the form or declare itin every Private Sub and set it to nothing in every Private Sub?
    To give is always to be NOBLE...
    To received is always to be BLESSED....
    Each day strive to be NOBLE
    Each day strive to be BLESSED

    If this post has helped you. Please take time to rate it.

    >=|+|=< Simply Me >=|+|=<

    ----------------------------------------
    Connection Strings | Number Only in Textbox | Splash Screen with Progress Bar | Printing to 1/2 of perforated bond paper |
    Freeze 2005 DataGridView Column

  2. #2
    Lively Member
    Join Date
    May 2002
    Posts
    83

    Re: Need to be clarified

    1) You use rs.open when you want to open a recordset (SELECT). You use oConn.execute when you running a query that doesn't return a recordset(INSERT, UPDATE, DELETE, etc.)

    2) Not sure what you're asking. Are you asking if you have to check the state and close the recordset before trying to open again?

    3) I prefer to declare what I'm using locally in the local sub, if more than one sub needs access to something I declare it in the module's general declarations, otherwise it stays local. If for no other reason, it's helps me make sure that I deal with variables that are only local locally. So more directly, I would declare it locally in each sub.

  3. #3
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Need to be clarified

    3. No, but you should do it because it does eliminate problems when you have a problem with your SQL statement execution and need to know exactly what the statement looks like. Then you can simply put a statement between the two

    Debug.Print SQL

    or put a breakpoint on the next line so you can see what the SQL statement looks like.

  4. #4

    Thread Starter
    PowerPoster Simply Me's Avatar
    Join Date
    Aug 2003
    Posts
    2,748

    Re: Need to be clarified

    Thanks for the explanation.
    Quote Originally Posted by morleyz
    1) You use rs.open when you want to open a recordset (SELECT). You use oConn.execute when you running a query that doesn't return a recordset(INSERT, UPDATE, DELETE, etc.)
    Yes, that's is what im asking.
    Quote Originally Posted by morleyz
    1)
    2) Not sure what you're asking. Are you asking if you have to check the state and close the recordset before trying to open again?
    Meaning it depends on the situation, right?
    Quote Originally Posted by morleyz
    1)
    3) I prefer to declare what I'm using locally in the local sub, if more than one sub needs access to something I declare it in the module's general declarations, otherwise it stays local. If for no other reason, it's helps me make sure that I deal with variables that are only local locally. So more directly, I would declare it locally in each sub.
    To give is always to be NOBLE...
    To received is always to be BLESSED....
    Each day strive to be NOBLE
    Each day strive to be BLESSED

    If this post has helped you. Please take time to rate it.

    >=|+|=< Simply Me >=|+|=<

    ----------------------------------------
    Connection Strings | Number Only in Textbox | Splash Screen with Progress Bar | Printing to 1/2 of perforated bond paper |
    Freeze 2005 DataGridView Column

  5. #5

    Thread Starter
    PowerPoster Simply Me's Avatar
    Join Date
    Aug 2003
    Posts
    2,748

    Re: Need to be clarified

    What is No randem?
    To give is always to be NOBLE...
    To received is always to be BLESSED....
    Each day strive to be NOBLE
    Each day strive to be BLESSED

    If this post has helped you. Please take time to rate it.

    >=|+|=< Simply Me >=|+|=<

    ----------------------------------------
    Connection Strings | Number Only in Textbox | Splash Screen with Progress Bar | Printing to 1/2 of perforated bond paper |
    Freeze 2005 DataGridView Column

  6. #6
    Lively Member
    Join Date
    May 2002
    Posts
    83

    Re: Need to be clarified

    Yes, #3 depend on the situation and I don't think either way is wrong or right...just different.

    As far as #2 goes. I don't normally have to check if the recordset is already open because I keep careful track of recordsets in my code (always closing recordsets when I'm done with them). That being said, if you try to rs.open a recordset that's already open, you'll get an error. So if you don't know for sure, you should probably check.

  7. #7

    Thread Starter
    PowerPoster Simply Me's Avatar
    Join Date
    Aug 2003
    Posts
    2,748

    Re: Need to be clarified

    Thanks to both of you!
    To give is always to be NOBLE...
    To received is always to be BLESSED....
    Each day strive to be NOBLE
    Each day strive to be BLESSED

    If this post has helped you. Please take time to rate it.

    >=|+|=< Simply Me >=|+|=<

    ----------------------------------------
    Connection Strings | Number Only in Textbox | Splash Screen with Progress Bar | Printing to 1/2 of perforated bond paper |
    Freeze 2005 DataGridView Column

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