如何在同一个asp页面中连接2个mySQL表?

时间:2016-02-09 21:33:07

标签: mysql database asp-classic

我有一个ASP经典页面,可以很好地检索mySQL记录。我想使用页面的第一个作为标题记录。然后,另一个表在许多记录中都有详细信息,我想在下面显示。像零件号一样,然后显示那些零件的订单: 葡萄园:名称,位置,电话,网站   葡萄酒:种类,品种,风味,价格

我有一个页面返回零件编号信息,另一个页面返回详细信息,但是当我在同一页面上组合两个数据类时,它会中断。具有讽刺意味的是,我正在转向mySQL,但当前的页面正在使用Frontpage ASP编程,并且它与Access数据库一起使用效果很好。

以下是页面上半部分的代码:

<% 
'declare the variables 
Dim Connection
Dim ConnectionString
Dim Recordset
Dim SQL
Dim rsVineyard


'declare the SQL statement that will query the database
SQL = "SELECT * FROM Vineyards WHERE ID =" & Server.HtmlEncode(Request("V"))

'define the connection string, specify database driver
ConnString = "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=hosted.com; DATABASE=WineDB; UID=WineDB; PASSWORD=WinePasword; OPTION=3"

'create an instance of the ADO connection and Recordset objects
Set Connection = Server.CreateObject("ADODB.Connection")
Set rsVineyard = Server.CreateObject("ADODB.RecordSet")

'Open the connection to the database
Connection.Open ConnString

'Open the Recordset object executing the SQL statement and return records 
rsVineyard.Open SQL,Connection

%>

<% 

'first of all determine whether there are any records 
If rsVineyard.EOF Then 
Response.Write("No records returned.") 
Else 
'if there are records then loop through the fields 
Do While NOT rsVineyard.Eof   
%>

然后这是页面下半部分的Wines代码:

<% 
'declare the variables 
Dim wConnection
Dim wConnString
Dim rsWines
Dim wSQL

'declare the SQL statement that will query the database
wSQL = "SELECT * FROM Wines WHERE Winery_Number = 21 Order By Type DESC, Name ASC, Vintage ASC"

'define the connection string, specify database driver
ConnString = "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=hosted.com; DATABASE=WineDB; UID=WineDB; PASSWORD=WinePasword; OPTION=3"

'create an instance of the ADO connection and Recordset objects
Set wConnection = Server.CreateObject("ADODB.Connection")
Set rsWines = Server.CreateObject("ADODB.Recordset")

'Open the connection to the database
wConnection.Open wConnString

'Open the Recordset object executing the SQL statement and return records 
rsWines.Open wSQL,wConnection

'first of all determine whether there are any records 
If rsWines.EOF Then 
    rsWines.Write("No records returned.") 
Else 
'if there are records then loop through the fields 
    Do While NOT rsWines.Eof 
%>

同样,他们自己工作得很好,但是当我在一个页面中组合代码时,它就会出错。我甚至尝试使用include语句来引入第二页,但同样的错误。

0 个答案:

没有答案