Help with SQL Queries in ASP

A

akwarisk

I am currently working on a project that consists of two files. I
want to be able to dynamically select and display queries. Below are
my html and asp pages. Can someone tell me what I am doing wrong and
give me some insight into how to fix the problem.

I do not know where to insert this query so that it will be displayed
whenever I choose it from the drop down box in the html page.

SELECT [Product List].ProductID,
[Product List].ProductName
FROM Products AS [Product List]
WHERE ((([Product
List].Discontinued)=No))
ORDER BY [Product List].ProductName;

THIS IS MY HTML PAGE
<html>
<head>
<title>MIS 320 Project</title>
<script type="text/javascript" language=Javascript>
var xmlHttp

function showqueries(str){
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Your browser does not support AJAX!");
return;
}
var url="queriesPage.asp";
url=url+"?queries="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);

}

function stateChanged() {
if (xmlHttp.readyState==4)
{
document.getElementById("txtHint").innerHTML=xmlHttp.responseText;

}
}

function GetXmlHttpObject(){
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}

</script>

</head>
<body>

<body bgcolor="#0099FF">

<h1><center>Queries</center></h1>

<br>

<form>
Select a table name:
<select name="queries" onchange="showqueries(this.value)">

<option value="Current Product List">Current Product
List</option value>

</select>

</form>

<p>
<div id="txtHint"><b>Customer info will be listed here.</b></
div>
</p>

<pre>
<br>
<br>
<br>

<br>
<br>
<center><A HREF="index.asp">Index.asp</A> <A
HREF="tables.asp">Tables.asp</A> <A HREF="update.asp">Update.asp</A>
<A HREF="salesReport.asp">SalesReport.asp</A></center> <br>
</pre>

</body>
</html>

THIS IS MY ASP PAGE:
<%

sql="SELECT * FROM " & request.querystring("queries") & ";"

response.write("SQL COMMAND --> (" & sql & ")<--")

set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.MapPath("Northwind2.mdb"))
set rs = Server.CreateObject("ADODB.recordset")
rs.Open sql, conn

response.write("<table>")
response.write("<body>")
do until rs.EOF

response.write("<tr>")

for each x in rs.Fields

response.write("<td>" & x.value & "</td>")
next

response.write("</tr>")

rs.MoveNext
loop
response.write("</body>")
response.write("</table>")
%>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top