psv 高达破坏者2怎么样:菜鸟求救!关于ASP查找ACCESS数据表内相符的数据

来源:百度文库 编辑:神马品牌网 时间:2024/05/03 13:03:37
我想在网页中实现输入产品编号就能查找到相符的记录
现有ACCESS数据库,表:product 字段名:product_id
哪位大哥帮我写一段代码,本人感激不尽啊!

第一步:打开数据库
conn.asp
<%
dim connstr,mysql,myconn
connstr="provider=microsoft.jet.oledb.4.0;data source="& server.mappath("jd.mdb")
set myconn=server.createobject("adodb.connection")
myconn.connectionstring=connstr
myconn.open
%>

第二步:提交查询页面
index.htm
<form method="POST" action="chaxun.asp">
<p>输入产品号:<input type="text" name="T1" size="20">
<input type="submit" value="提交" name="B1"><input type="reset" value="重置" name="B2"></p>
</form>

第三步:显示查询结果
chaxun.asp

<!-- #include file=conn.asp -->
<%

dim cpbh
cpbh=request.form("T1") //接受产品编号

mySQL="select * from product where product_id='" & cpbh& "'"
set myRes=myconn.execute(mySQL)

if myres.bof and myres.eof then //产品编号不存在
response.write"产品编号不存在"
else
%>

<%=product_id %> //产品编号
<%=product_name %> //产品名称
.................
<%end if%>

<%
Set rs = Server.CreateObject("ADODB.Recordset")
If lx="不限" then
sql="select * from rsgq where lx like '%"&searchkey&"%' and sh = 1 and yxq >= '"&sj&"' order by jlid desc"
Else
sql="select * from rsgq where lx like '%"&searchkey&"%' and sh = 1 and yxq >= '"&sj&"' and classname = '"&lx&"' order by jlid desc"
End If
rs.open sql,conn,1,1
rs.pagesize=20
tatalrecord=rs.recordcount
tatalpages=rs.pagecount
if rs.recordcount=0 then
response.write "<Script Language=JavaScript>alert('对不起,没有搜索到相关记录!');history.back(-1)</Script>"
response.End
Else
rs.movefirst
nowpage=request("page")
if nowpage&"x"="x" then
nowpage=1
else
nowpage=cint(nowpage)
end if
rs.absolutepage=nowpage
n=1
while not rs.eof and n<=rs.pagesize
%> <tr>
<td height="23" valign="top">
<table width="100%" height="28" border="0" cellpadding="2" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td width="1%" height="26" valign="middle">
<div align="center"><img border="0" src="images/arrow_01.gif"></div></td>
<td width="9%"><font color="#478B47">[<a href="index.asp?lx=<%=trim(rs("classname"))%>" title="查看所有<%=trim(rs("classname"))%>信息"><%=trim(rs("classname"))%></a>]</font></td>
<td width="66%"><font color="#478B47"><a href="read.asp?id=<%=Rs("jlid")%>" title="<%=Trim(Rs("lx"))%>" target="_blank"><%If Len(Rs("lx"))>18 Then%><%=Left(Rs("lx"),18)%><%Else%><%=Trim(Rs("lx"))%><%End If%></a></font></td>
<td width="12%" align="center"><%=rs("hit")%></td>
<td width="12%" align="center"><a href="diqu.asp?dq=<%=Trim(rs("dq"))%>"><%=rs("dq")%></a></td>
</tr>
</table>
<%
url="search.asp?search="&searchkey&"&lx="&lx&"&"
n=n+1
rs.movenext
wend
rs.close
set rs=nothing
%>

这段代码是一段搜索代码,不知道楼主是不是想要这个?总之,如果想搜索某一个字段的话就在where后面加 字段名 like "%变量名%"