Results 1 to 14 of 14

Thread: Opening 2 or more tables?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Location
    Philippines
    Posts
    246

    Opening 2 or more tables?

    How can I open two tables at once,
    I tried this code but it didn't worked for me:

    vb Code:
    1. Dim rs As ADODB.Recordset
    2.     Set rs = New ADODB.Recordset
    3.     rs.CursorLocation = adUseClient
    4.     rs.CursorType = adOpenStatic
    5.     rs.LockType = adLockReadOnly
    6.     rs.Open "SELECT * FROM avatar,singleplayername", conn, adOpenStatic, adLockOptimistic
    7.    
    8.     swfUserProfile.SetVariable "txtPlayerName", rs!playerName
    9.     swfPictureAvatar.LoadMovie 1, rs!avatarFile
    10.     swfPictureAvatar.Movie = rs!avatarFile
    11.    
    12.     rs.Close
    13.     Set rs = Nothing

    Need Help

  2. #2
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Opening 2 or more tables?

    Sorry each table needs a sperate select statement. Are they related in some way?
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Location
    Philippines
    Posts
    246

    Re: Opening 2 or more tables?

    They came from the same database, how can I fix it?

  4. #4
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Opening 2 or more tables?

    You write two select statements. Or if the tables are related in someway (they hold information about someone some stuff in one table and other stuff in the other) then you do a select from both tables using an Inner Join.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Location
    Philippines
    Posts
    246

    Re: Opening 2 or more tables?

    Can I have an example of using select statement with Inner Join?

    Thanks. Sorry for bothering.

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

    Re: Opening 2 or more tables?

    You can, but we need information from you first.. what fields are in each table? which field(s) are used to link them together?

    It would probably help if you show a couple of example rows of data from each table.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Location
    Philippines
    Posts
    246

    Re: Opening 2 or more tables?

    These are the fields for the avatar table:
    1. avatarNumber
    2. avatarName
    3. avatarSize
    4. avatarFile <----- Location only

    These are fields for the singleplayername table:
    1. playerNumber
    2. playerName

    I'm just trying to call them both all at once at the Form_Load()
    So the user can choose his or her name and avatar.

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

    Re: Opening 2 or more tables?

    Ok, there appears to be no related data at all - what we expected to see was something like the Player table having a field (perhaps called avatarNumber) which refers to a specific row in the Avatar table.

    As that isn't the way you have it, a Join is not apt. Instead you should open two separate Recordsets, one for each table.

  9. #9
    Member
    Join Date
    Nov 2006
    Posts
    38

    Re: Opening 2 or more tables?

    Quote Originally Posted by si_the_geek
    Ok, there appears to be no related data at all - what we expected to see was something like the Player table having a field (perhaps called avatarNumber) which refers to a specific row in the Avatar table.

    As that isn't the way you have it, a Join is not apt. Instead you should open two separate Recordsets, one for each table.

    hey i remember that you can do multiple select right??? that is why there is "NEXTRECORDSET" procedure on ADO?? i dont know if this is correct...

    but how to do this i do not remember...try putting this ";" after each statement...

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

    Re: Opening 2 or more tables?

    That would be possible but wouldn't really gain much, it would just mean that there was only one recordset variable (with separate code blocks) instead of two - I think belvita would find it less confusing to have two separate ones.

  11. #11
    Member
    Join Date
    Nov 2006
    Posts
    38

    Re: Opening 2 or more tables?

    Quote Originally Posted by si_the_geek
    That would be possible but wouldn't really gain much, it would just mean that there was only one recordset variable (with separate code blocks) instead of two - I think belvita would find it less confusing to have two separate ones.
    hahaha...im just going with the idea of the two SELECT statements. coz i just remembered that it was kinda' possible..im sorry to have mislead.

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

    Re: Opening 2 or more tables?

    There are times when it is a good idea (otherwise it wouldn't be an option!), but in my opinion this isn't one of them.. it is debatable tho, so mentioning it wasn't a bad thing.

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Location
    Philippines
    Posts
    246

    Re: Opening 2 or more tables?

    Two select statement? like this one?

    rs.Open "SELECT * FROM avatar"
    rs.Open "SELECT * FROM singleplayername"

    Is this the right syntax?

    I'd tried this but it didn't worked for me.

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

    Re: Opening 2 or more tables?

    Something like this:
    Code:
          Dim rs As ADODB.Recordset
              Set rs = New ADODB.Recordset
    
              rs.Open "SELECT * FROM singleplayername", conn, adOpenForwardOnly, adLockReadOnly
              swfUserProfile.SetVariable "txtPlayerName", rs!playerName
              rs.Close
    
              rs.Open "SELECT * FROM avatar", conn, adOpenForwardOnly, adLockReadOnly
              swfPictureAvatar.LoadMovie 1, rs!avatarFile
              swfPictureAvatar.Movie = rs!avatarFile         
              rs.Close
    
              Set rs = Nothing
    Note however that as you are not using a Where clause with the SQL statements, you cannot tell which record will be read from each table (assuming each table has more than one record).

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