Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 17th, 2004, 12:00 AM
Authorized User
 
Join Date: Jan 2004
Location: Oklahoma City, , .
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!

Reply With Quote
  #2 (permalink)  
Old March 17th, 2004, 05:09 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
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
Reply With Quote
  #3 (permalink)  
Old March 18th, 2004, 12:01 AM
Authorized User
 
Join Date: Jan 2004
Location: Oklahoma City, , .
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
%>

Reply With Quote
  #4 (permalink)  
Old March 18th, 2004, 04:38 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
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
Reply With Quote
  #5 (permalink)  
Old March 18th, 2004, 07:48 PM
Authorized User
 
Join Date: Jan 2004
Location: Oklahoma City, , .
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
----^


Reply With Quote
  #6 (permalink)  
Old March 19th, 2004, 04:49 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
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.
Reply With Quote
  #7 (permalink)  
Old March 19th, 2004, 10:46 AM
Authorized User
 
Join Date: Jan 2004
Location: Oklahoma City, , .
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That worked! Thank you!

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 05:06 AM.


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