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

Thread: recordset

  1. #1
    Join Date
    Jan 2000
    Location
    Saskatchewan, Canada
    Posts
    595

    recordset

    Is it possible to join more than 2 tables to an updateable recordset? If so how?
    thanks


  2. #2
    Guest

    Re: recordset

    "Draw" query in Access (or view in SQL Server). Switch to SQLView (if Access, in SQL Server you see sql statement at the same time). Copy that SQL statement to VB and use it for creating a recordset. As an example you can open Nwind database and check existing queries.
    Vlad


  3. #3
    Join Date
    Feb 2000
    Posts
    137

    Re: recordset

    Use the TSQL keyword JOIN in your SQL statement that you use to generate your recordset - for example:

    Given - Table: Table1 has fields f1 and f2
    Table: Table2 has fields f3 and f4

    to join these tables in a recordset use a SQL statement similar to the following:

    "Select a.f1, a.f2, b.f3, b.f4 From Table1 a JOIN Table2 b ON a.f1 = b.f3"

    In the above select statement, it is assumed that Table1.f1 and Table2.f3 contain the same information (one may even be a foreign key to the other table). It is necessary that there be a field in both tables that the tables can be tied together with (this is what ties the related records from one table to the records in the primary table, hence the term "relational database").

    Hope this helps.


  4. #4
    Join Date
    Feb 2000
    Posts
    137

    Re: recordset

    Sorry I hit the continue key before I was ready. To continue...

    The a and b in the statement are aliases for the tables - that way you can even join tables whose fields have the same name (if both tables in the previous example had fields named f1 and f2 they would be distinguished as a.f1, b.f1, a.f2, b.f2) - you can join as many tables this way as needed. There also are serveral types of joins "LEFT OUTER JOIN" "RIGHT OUTER JOIN" etc, I would suggest that you look up the types of joins available and how they affect the recordset that is returned to determine what type of join to use.


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