万锌良所有电影大全:求助!头都大了,关于asp连接数据库问题,在线等!!

来源:百度文库 编辑:高考问答 时间:2024/05/04 04:43:41
首先这段代码用于提取URL中的st_class_name
st_class_name=request.querystring("st_class_name")
然后在表单中(含附件上传的表单即有enctype="multipart/form-data")有
读取数据库建立下拉选框
------------------------------
<select name="st_class">
<option value="" selected>请选择</option>
<%
set rs=server.CreateObject("adodb.recordset")
sql="select * from type_class where type_where='&st_class_name&' order by type_id asc"
rs.open sql,conn,1,1
if rs.eof and rs.bof then %>
<font color="#666666">对不起!暂时还没有关于[<%=class_write%>]的分类!</font>
<%else
do while not rs.eof %>
<option value="<%=rs("type_id")%>"><%=rs("type_name")%></option>
<%rs.movenext
loop
rs.close
set rs=nothing
end if%>
</select>
--------------------------------
结果这段数据库根本就读不出来,但这个变量st_class_name能在表单中正确显示出来
其中conn.asp文件为
-----------------------------
<%
'connstr="DBQ="+server.mappath("admin/data/main.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
connstr="DBQ="+server.mappath("admin/data/main.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
set conn=server.createobject("ADODB.CONNECTION")
conn.open connstr
%>
---------------------------
哪位能帮忙一下,到底怎么回事,10分做为感激,本人的分数就这么点了
呵呵
感激不尽
刚才发现type_where='&st_class_name&'
换成
type_where like '%"&st_class_name&"%'
就可以了
不理解
有没有高人给解释一下啊

你把type_where='&st_class_name&'
换成
type_where='"&st_class_name&"'
也可以,
只不过like是模糊搜索,
问题的关键在于你没有加""
如果st_class_name=****,
那么sql就是
sql="select * from type_class where type_where='****' order by type_id asc"

%是通配符,就像*一样。
type_where like '%"&st_class_name&"%'
这句还是不对,应为
"type_where like '%"&st_class_name&"%'"才对

sql="select * from type_class where type_where='&st_class_name&' order by type_id asc"

写成
sql="select * from type_class where type_where='" & st_class_name & "' order by type_id asc"

加引号