0

考虑到以下情况,我想知道链接中的以下使用是否正确

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 时,它应该打开查询 where number between 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>
4

1 回答 1

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
%>
于 2012-06-15T11:58:42.263 回答