DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Max Guest

    Multiple Recordset from two tables


    I am new in the .asp world. I have two different tables in my database (Items
    & Categories) I would like to know if it is possible to retrieve a few columns
    from one table and a few more from the other and combine the results to the
    same asp page on the browser.

    I can be more specific if needed.

    Thank you,

    Max

  2. #2
    Rama Ramachandran Guest

    Re: Multiple Recordset from two tables


    Use a SQL JOIN statement to join the two tables on some field that is common
    (maybe Category ID).

    The syntax will be

    Select Table1.Field1, Table1.Field2, ... Table2.Field1, Table2.Field2...
    FROM Table1 INNER JOIN Table2 ON
    Table1.CommonField = Table2.CommonField

    You will then get a recordset with all the fields you requested, where the
    common fields are equal among the two tables. You can treat this recordset
    like a recordset you fetch from a single table, and dump its contents on
    to the browser using Response.Write







    "Max" <maxthemenace@hotmail.com> wrote:
    >
    >I am new in the .asp world. I have two different tables in my database (Items
    >& Categories) I would like to know if it is possible to retrieve a few columns
    >from one table and a few more from the other and combine the results to

    the
    >same asp page on the browser.
    >
    >I can be more specific if needed.
    >
    >Thank you,
    >
    >Max



  3. #3
    Max Guest

    Re: Multiple Recordset from two tables


    Thank you for your reply

    Ok i got it to work the way you told me. thank you.

    One more question.

    I have made a Add .asp page so i can add records to the database. Well is
    there anyway that one field on the form can be saved to two different tables
    in my database. Lets say I want the "First Name" Paul to be added to the
    column "name" in the "Items" table, and also saved on the column "name" in
    the "categories" table ?

    Do you understand what I mean.

    Thank you for your help
    Icq: 41680239

    Max


  4. #4
    KAJ Guest

    Re: Multiple Recordset from two tables


    hi max
    if i have understood you problem correctly, what you need
    is a JOIN query
    ____________________________________________________
    e.g.
    select Items.itemname, Categories.categoryname from
    Items,Categories where Items.Ino=Categories.Ino
    ____________________________________________________
    You can execute this query to get a recordset by
    ____________________________________________________
    Set Con = Server.CreateObject( "ADODB.Connection" )
    Con.Open "DRIVER={SQL Server};
    SERVER=ServerName;
    UID=UserID;
    pwd=password;
    DATABASE=dbname"

    Dim SqlX
    SqlX = "select Items.itemname,
    Categories.categoryname
    from Items,Categories where Items.Ino=Categories.Ino"

    Dim RSX
    Set RSX = Con.Execute(SqlX)
    ____________________________________________________
    Now RSX(0) is the itemname from Items table
    and RSX(1) is the categoryname from Categories table
    ____________________________________________________





    "Max" <maxthemenace@hotmail.com> wrote:
    >
    >I am new in the .asp world. I have two different tables in my database (Items
    >& Categories) I would like to know if it is possible to retrieve a few columns
    >from one table and a few more from the other and combine the results to

    the
    >same asp page on the browser.
    >
    >I can be more specific if needed.
    >
    >Thank you,
    >
    >Max



  5. #5
    Shawn Guest

    Re: Multiple Recordset from two tables


    Max,
    I don't know of a simple way to do that in one statement. What I would
    recommend is to create a stored procedure (Query Def if you are using Access)
    that contains two insert statements. You can then call your stored procedure
    from your ASP code. The procedure would look something like this:

    create procedure PostData (@fname as varchar(30)) as
    begin tran --Ensures that if one of the inserts fails, both do
    insert into items (name) values (@fname)
    insert into categories (name) values (@fname)
    commit tran
    go

    When you call the procedure from asp, just do something like this:
    cnnDB.execute "PostData 'Joe'"


    "Max" <maxthemenace@hotmail.com> wrote:
    >
    >Thank you for your reply
    >
    >Ok i got it to work the way you told me. thank you.
    >
    >One more question.
    >
    >I have made a Add .asp page so i can add records to the database. Well is
    >there anyway that one field on the form can be saved to two different tables
    >in my database. Lets say I want the "First Name" Paul to be added to the
    >column "name" in the "Items" table, and also saved on the column "name"

    in
    >the "categories" table ?
    >
    >Do you understand what I mean.
    >
    >Thank you for your help
    >Icq: 41680239
    >
    >Max
    >



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links