Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 17th, 2004, 12:00 AM
Authorized User
 
Join Date: Jan 2004
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Default Pull info from 2 tables

This is probably pretty simple, but how do I pull information from two different tables on the same page without getting any errors? Thanks for your help!

 
Old March 17th, 2004, 05:09 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

If you want to combine the data from the 2 tables into 1 recordset you need to look at SQL JOIN syntax.

If you want the data separate you need 2 recordsets.

Can you give more detail? If you have some code at the moment which doesn't work then post it here and we'll take a look :D

rgds
Phil
 
Old March 18th, 2004, 12:01 AM
Authorized User
 
Join Date: Jan 2004
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I actually have one page and wanted to use SSI to include two different files that each pull from a different table. Here are the codes I have for each include page....

Page 1:

<%
Dim adoCon
Dim rsSchoolClosing
Dim strSQL
set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("/stacygraff/database/mercy.mdb")
Set rsSchoolClosing = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT tblSchoolClosing.* FROM tblSchoolClosing;"
rsSchoolClosing.Open strSQL, adoCon

Do While Not rsSchoolClosing.EOF
    Response.Write ("<img src="../images/arrow1.gif" width="31" height="21"> "
    Response.Write (rsSchoolClosing("Description"))
rsSchoolClosing.MoveNext
Loop

rsSchoolClosing.Close
Set rsSchoolClosing = Nothing
Set adoCon = Nothing
%>

Page 2:

  <%
Dim adoCon
Dim rsNews
Dim strSQL2
set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("/stacygraff/database/mercy.mdb")
Set rsNews = Server.CreateObject("ADODB.Recordset")
strSQL2 = "SELECT tblNews.* FROM tblNews;"
rsNews.Open strSQL2, adoCon
Response.Write ("<table border=""1"" cellpadding=""5"">")
Do While Not rsNews.EOF
    Response.Write ("<tr>")
    Response.Write ("<td>")
    Response.Write (rsNews("NewsInfo"))
    Response.Write ("</td>")
    Response.Write ("<td>")
    Response.Write ("<a href=""updatenewsform.asp?ID=" & rsNews("NewsID") & """>")
    Response.Write ("Edit")
    Response.Write ("</td>")
    Response.Write ("<td>")
    Response.Write ("<a href=""deletenewsentry.asp?ID=" & rsNews("NewsID") & """>")
    Response.Write ("Delete")
    Response.Write ("</td>")
    Response.Write ("</tr>")

    rsNews.MoveNext
Loop

Response.Write ("</table>")

rsNews.Close
Set rsNews = Nothing
Set adoCon = Nothing
%>

 
Old March 18th, 2004, 04:38 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

The only thing I can see that might cause you problems is that both include files Dim the same variable "adoCon". What error(s) are you getting?

A couple of other comments about the way you're doing things:
1. you shouldn't use the Access ODBC driver in ASP, you should use the Jet OLEDB driver instead (see here http://www.able-consulting.com/ADO_Conn.htm for connection string examples)
2. why do you do SELECT * for both recordsets when you only need 1 or 2 fields out of each table? It's more efficient to only select the fields you are going to use.

hth
Phil
 
Old March 18th, 2004, 07:48 PM
Authorized User
 
Join Date: Jan 2004
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is the error I get...

Microsoft VBScript compilation error '800a0411'

Name redefined

/stacygraff/managementarea/Admin/incnews.asp, line 6

Dim adoCon
----^


 
Old March 19th, 2004, 04:49 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Yes, you get that error because you are trying to define (Dim) the variable adoCon twice - you need to rename it in either one of your include pages.
 
Old March 19th, 2004, 10:46 AM
Authorized User
 
Join Date: Jan 2004
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That worked! Thank you!






Similar Threads
Thread Thread Starter Forum Replies Last Post
How to pull excel data into oracle tables yogeshyl Oracle 1 January 9th, 2008 12:38 PM
Getting info from two tables Fernb2000 SQL Language 1 August 9th, 2005 11:20 PM
To Pull my java Interface, via JSP Befekadu Pro JSP 1 March 9th, 2005 06:56 PM
Pull or Push? sureshvb Crystal Reports 0 August 23rd, 2004 01:13 AM
Pull years from date field kev_79 Access 2 August 2nd, 2004 01:49 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.