473,405 Members | 2,354 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

query different databases from the same page

229 100+
Hi, I wonder if anyone can tell me the trick to query two different databases with two dropdowns.

I have two dropdowns. One is included as an include. At the top of the page I have one database connection:

Expand|Select|Wrap|Line Numbers
  1. <%@ Language=VBScript %>
  2. <!--#Include File="miniart/dbconnect.asp"-->
  3. <%
  4.  
  5. Dim oRs, conn, connect, strSQL
  6.  
  7. set conn=server.CreateObject ("adodb.connection")
  8. connect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("/mini.mdb") & ";Persist Security Info=False"
  9. conn.Open connect

I need the second one to query a different database...anyone any ideas?

Thanks for any help.
Richard





Expand|Select|Wrap|Line Numbers
  1. <select  onChange="window.location='http://www..com/mane.asp?CardDescription=' + this.options[this.selectedIndex].value">
  2. <OPTION VALUE = art>&nbsp;art Option>
  3. <OPTION>-----------------------------------------------------</Option>
  4. <%        
  5.     Set oRs=Server.CreateObject("adodb.recordset")
  6.     strSQL = "SELECT DISTINCT CardDescription FROM tblCards Where CategoryID <> " & 60 & " and CategoryID<>" & 61 & " ORDER BY Description"
  7. 'strSQL = "SELECT DISTINCT CardDescription FROM tblCards Where CategoryID<>" & 61 & "  ORDER BY CardDescription"
  8.  
  9.     oRs.Open strSQL, conn        
  10.  
  11.     Do while not oRs.EOF
  12.         if Request.Form("GreetingPostCards") = oRs("CardDescription") then 'if this is the selected one then display as selected
  13.             Response.Write "<OPTION VALUE = '" & oRS ("CardDescription") & "' SELECTED>"
  14.             Response.Write oRs("CardDescription") & "</Option>"
  15.             oRs.MoveNext 
  16.         else
  17.             Response.Write "<OPTION VALUE = '" & oRs ("CardDescription") & "'>&nbsp;"
  18.             Response.Write oRs("CardDescription") & ",</Option>"
  19.             oRs.MoveNext 
  20.         end if
  21.     loop        
  22.     %>
  23. </SELECT>
  24. </div>
  25.   </form>
Apr 28 '08 #1
3 1636
fran7
229 100+
Just thought I would say I worked this one out.

Putting this at the beginning of each drop down and directing them to the different databases did the trick

Expand|Select|Wrap|Line Numbers
  1.         set conn=server.CreateObject ("adodb.connection")
  2. connect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &_
  3.       Server.MapPath("/the two databases.mdb") & ";Persist Security Info=False"
  4. conn.Open connect
Thanks
Richard
Apr 28 '08 #2
danp129
323 Expert 256MB
Hi, I wonder if anyone can tell me the trick to query two different databases with two dropdowns.

I have two dropdowns. One is included as an include. At the top of the page I have one database connection:

Expand|Select|Wrap|Line Numbers
  1. <%@ Language=VBScript %>
  2. <!--#Include File="miniart/dbconnect.asp"-->
  3. <%
  4.  
  5. Dim oRs, conn, connect, strSQL
  6.  
  7. set conn=server.CreateObject ("adodb.connection")
  8. connect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("/mini.mdb") & ";Persist Security Info=False"
  9. conn.Open connect

I need the second one to query a different database...anyone any ideas?

Thanks for any help.
Richard





Expand|Select|Wrap|Line Numbers
  1. <select  onChange="window.location='http://www..com/mane.asp?CardDescription=' + this.options[this.selectedIndex].value">
  2. <OPTION VALUE = art>&nbsp;art Option>
  3. <OPTION>-----------------------------------------------------</Option>
  4. <%        
  5.     Set oRs=Server.CreateObject("adodb.recordset")
  6.     strSQL = "SELECT DISTINCT CardDescription FROM tblCards Where CategoryID <> " & 60 & " and CategoryID<>" & 61 & " ORDER BY Description"
  7. 'strSQL = "SELECT DISTINCT CardDescription FROM tblCards Where CategoryID<>" & 61 & "  ORDER BY CardDescription"
  8.  
  9.     oRs.Open strSQL, conn        
  10.  
  11.     Do while not oRs.EOF
  12.         if Request.Form("GreetingPostCards") = oRs("CardDescription") then 'if this is the selected one then display as selected
  13.             Response.Write "<OPTION VALUE = '" & oRS ("CardDescription") & "' SELECTED>"
  14.             Response.Write oRs("CardDescription") & "</Option>"
  15.             oRs.MoveNext 
  16.         else
  17.             Response.Write "<OPTION VALUE = '" & oRs ("CardDescription") & "'>&nbsp;"
  18.             Response.Write oRs("CardDescription") & ",</Option>"
  19.             oRs.MoveNext 
  20.         end if
  21.     loop        
  22.     %>
  23. </SELECT>
  24. </div>
  25.   </form>
It's not clear when you are wanting to query the other database. You can create a connection to a seperate database like this

Expand|Select|Wrap|Line Numbers
  1. Dim oRs, conn, connect, strSQL, conn2, connect2
  2.  
  3. 'first connection
  4. set conn=server.CreateObject ("adodb.connection")
  5. connect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("/mini.mdb") & ";Persist Security Info=False"
  6. conn.Open connect
  7.  
  8. 'second connection
  9. set conn2=server.CreateObject ("adodb.connection")
  10. connect2 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("/otherdb.mdb") & ";Persist Security Info=False"
  11. conn2.Open connect2
  12.  
  13.  
  14. 'query connection 2 using another recordset (if first recordset still open, otherwise just use oRS
  15. Dim oRs2
  16. Set oRs2=Server.CreateObject("adodb.recordset")
  17.  
  18. strSQL="blah blah blah"
  19. oRs2.Open strSQL, conn2
  20.  
  21.  
Apr 28 '08 #3
danp129
323 Expert 256MB
Just thought I would say I worked this one out.

Putting this at the beginning of each drop down and directing them to the different databases did the trick

Expand|Select|Wrap|Line Numbers
  1.         set conn=server.CreateObject ("adodb.connection")
  2. connect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &_
  3.       Server.MapPath("/the two databases.mdb") & ";Persist Security Info=False"
  4. conn.Open connect
Thanks
Richard
Yes you can (and should) do it that way if you know you don't need the first connection anymore sometimes you will.
Apr 28 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: wimmie | last post by:
Hello to all, I have a 'small' problem. I have made a application in php that connect trough ODBC to a Oracle RDB (VMS) or Basis+ database (VMS) and present the data to a user. There are 2...
2
by: Mattyboy | last post by:
Guys I have built a database with saved queries that runs fine in Access but when I call it from the web using ASP, an exception occurs. I have tried multiple ways of testing the databases with...
9
by: noor.rahman | last post by:
I was wondering how it may be possible to query 2 MySQL databases using one query statement from PHP. For instance: SELECT database1.tableA.field1 UNION database2.tableB.field2. My concern...
5
by: listerofsmeg01 | last post by:
Hi, Pretty new to PHP and MySQL. I have a page on my site that displays a lot of information from various tables. Currently I have lots of small PHP wrapper functions around SQL queries to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.