我想知道考虑到下面的场景,下面链接中的使用是否正确
main.asp页面
<a href="http://details.asp?number between 01 and 08>)
click here for number between 1 and 8
</a>
这是访问中的查询
select * from table
where right("000" & number,2) between [enter start number] and [enter end number]
这是访问中的表
number| field1| field2| field3
1 | xys | abc | at
2 |sdfd | dfasd | dd
3 | sdfd | ddd | dd
以下是details.asp代码
<html>
<body>
<%
Dim numCategoryID
numCategoryID = Request.Querystring("number")
set conn=Server.CreateObject("ADODB.Connection")
conn.open "query"
set rs = Server.CreateObject("ADODB.recordset")
strQuery = "queryname '" & numCategoryID & "'"
rs.Open strQuery, conn
%>
<table border="1" width="100%">
<tr>
<%for each x in rs.Fields
response.write("<th>" & x.name & "</th>")
next%>
</tr>
<%do until rs.EOF%>
<tr>
<%for each x in rs.Fields%>
<td><%Response.Write(x.value)%></td>
<%next
rs.MoveNext%>
</tr>
<%loop
rs.close
conn.close
%>
</table>
</body>
</html>
如果上述代码有任何错误,请告诉我。实际上,当我点击链接main.asp时,它应该打开1到8之间的数字查询。
这是我第三次尝试在用户输入表单
中的两个数字时在两个数字之间输出<%
dim startnumber, endnumber
startnumber = Request.form("number")
endnumber = Request.form("number")
set conn=Server.CreateObject("ADODB.Connection")
conn.open "connection"
set rs = Server.CreateObject("ADODB.recordset")
strQuery = "SELECT * from query " _
& "where number between" & startnumber_
& "& endnumber;
rs.Open strQuery, conn
%>
<table border="1" width="100%">
<tr>
<%for each x in rs.Fields
response.write("<th>" & x.name & "</th>")
next%>
</tr>
<%do until rs.EOF%>
<tr>
<%for each x in rs.Fields%>
<td><%Response.Write(x.value)%></td>
<%next
rs.MoveNext%>
</tr>
<%loop
rs.close
conn.close
%>
</table>
</body>
</html>
答案 0 :(得分:0)
这是一个有一些建议的重新设计的版本,如果它正常工作会让我感到惊讶,它只是给你一个想法,关于通过数字和从数据库中选择的部分可能与你想要的不同,无论如何检查您所请求的参数,只显示其余参数是否有正确值,否则显示消息
'no sql parts in your url, just parameters with a value
'this just indicates you want the numbers between 1 and 8,
'doesn't select a specific number,
'then you need eg a form with an input box in your main.asp page
'main.asp
<a href="http://details.asp?number=true>)
click here for number between 1 and 8
</a>
'details.asp
'best not mix html with code, using one code block here
w "<html>"
w " <body>"
dim number, conn, rs, connectionstring, strQuery
number = Request.Querystring("number")
if number then
'adapt the connectionstring for other versions of access and/or files
connectionString = "DBQ=" & Server.MapPath("\mydb.mdb") & ";DRIVER={Microsoft Access Driver (*.mdb)};"
set conn = Server.CreateObject("ADODB.Connection")
conn.open ConnectionString
'best to not be dependent on a query, put your sql here
'no need for an empty recordset first
strQuery = "select * from table where number between 1 and 8;"
set rs = conn.execute(strQuery)
w " <table border='1' width='100%'>"
w " <tr>"
for each x in rs.Fields
w " <th>" & x.name & "</th>"
next
w " </tr>"
do until rs.EOF
w " <tr>"
for each x in rs.Fields
w " <td>" & x.value & "</td>"
next
rs.MoveNext
w " </tr>"
loop
rs.close
conn.close
set conn = nothing 'close and cleanup your connection properly
w " </table>"
else
w "No parameter number found"
end if
w " </body>"
w "</html>"
'--- ---'
sub w (text)
response.write(text) & VbCrLf
end sub
%>
测试你的数据库连接制作像这样的asp
<%
on error resume next
connectionString = "DBQ=" & Server.MapPath("\mydb.mdb") & ";DRIVER={Microsoft Access Driver (*.mdb)};"
set conn = Server.CreateObject("ADODB.Connection")
conn.open ConnectionString
if err.number <> 0 then
response.write err.description
else
response.write "Connection was succesfull.."
end if
%>