ASP/VBScript/Database


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: ASP/VBScript/Database

  1. #1
    Bob Guest

    ASP/VBScript/Database


    Hi,

    I'm trying to collect data from two different table. How do I do that? Here
    is my code (using VBScript)

    //open connection to dabase server
    set DBConn = Server.CreateObject("ADODB.Connection")
    DBConn.Open (Application("A_Connection"))
    set rsAccount = Server.CreateObject("ADODB.RecordSet")
    rsAccount.CursorType=1
    rsAccount.activeConnection=DBConn

    sqlstring = "select cAreaCode, iPhone from account where iAccountId = "
    + CStr(Session("LoginId"))_
    + " order by iPhysicalPort"
    rsAccount.source = sqlstring
    rsAccount.open()

    //and some where down there, table1 columm1, I display out the data
    Response.Write("<TD><font color=blue size=2>" + rsAccount.fields("cAreaCode")
    + rsAccount.fields("cPhone") + "</font></TD>")

    I guess I can open another connection with the server... but ...can I collect
    data in both tables and display out in the same columm???

    Any help would greatly appreciated.
    -bob



  2. #2
    Andrew King Guest

    Re: ASP/VBScript/Database

    You can edit you SQL statement to pull the data from 2 tables - if they are
    related. Or you can use a second connection.

    Also look slike you have a typo. In your SQL you pull "iPhone" but in your
    response.write you use "cPhone".

    Andrew

    "Bob" <datsg_2000@yahoo.com> wrote in message
    news:3a1549d5$1@news.devx.com...
    >
    > Hi,
    >
    > I'm trying to collect data from two different table. How do I do that?

    Here
    > is my code (using VBScript)
    >
    > //open connection to dabase server
    > set DBConn = Server.CreateObject("ADODB.Connection")
    > DBConn.Open (Application("A_Connection"))
    > set rsAccount = Server.CreateObject("ADODB.RecordSet")
    > rsAccount.CursorType=1
    > rsAccount.activeConnection=DBConn
    >
    > sqlstring = "select cAreaCode, iPhone from account where iAccountId = "
    > + CStr(Session("LoginId"))_
    > + " order by iPhysicalPort"
    > rsAccount.source = sqlstring
    > rsAccount.open()
    >
    > //and some where down there, table1 columm1, I display out the data
    > Response.Write("<TD><font color=blue size=2>" +

    rsAccount.fields("cAreaCode")
    > + rsAccount.fields("cPhone") + "</font></TD>")
    >
    > I guess I can open another connection with the server... but ...can I

    collect
    > data in both tables and display out in the same columm???
    >
    > Any help would greatly appreciated.
    > -bob
    >
    >




  3. #3
    Evan Tate Guest

    Re: ASP/VBScript/Database

    Bob wrote:
    >
    > Hi,
    >
    > I'm trying to collect data from two different table. How do I do that? Here
    > is my code (using VBScript)
    >
    > //open connection to dabase server
    > set DBConn = Server.CreateObject("ADODB.Connection")
    > DBConn.Open (Application("A_Connection"))
    > set rsAccount = Server.CreateObject("ADODB.RecordSet")
    > rsAccount.CursorType=1
    > rsAccount.activeConnection=DBConn
    >
    > sqlstring = "select cAreaCode, iPhone from account where iAccountId = "
    > + CStr(Session("LoginId"))_
    > + " order by iPhysicalPort"
    > rsAccount.source = sqlstring
    > rsAccount.open()
    >
    > //and some where down there, table1 columm1, I display out the data
    > Response.Write("<TD><font color=blue size=2>" + rsAccount.fields("cAreaCode")
    > + rsAccount.fields("cPhone") + "</font></TD>")
    >
    > I guess I can open another connection with the server... but ...can I collect
    > data in both tables and display out in the same columm???
    >
    > Any help would greatly appreciated.
    > -bob

    Are the tables in any way related? Are they in the same database? If so,
    in your SQL Statement you can user INNERJOIN to link them into 1 SQL
    Statement and display info from both tables.

    If not in the same database, you'll have to use 2 connections I guess.
    Otherwise, it's always possible to display data from 2 tables, it just
    depends on HOW you want to do it.
    Attached Files Attached Files

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


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center