为什么我的代码无法实现数据库联动?

redrainy 2003-09-30 10:02:45
我希望在选择城市这个下来列表框时,在地县出现相应的地区,可是现在只在城市里看见有数据,而县里面没有.为什么呢?
<% Response.Buffer=True %>
<%Set Cnn = Server.CreateObject("ADODB.Connection")
StrCnn = "Provider=SQLOLEDB;Server=ahui;UID=sa;PWD=;Database=enterprise"
'strcnn= "Provider=Microsoft.JET.OLEDB.4.0;Data Source= "&server.MapPath("mdb/enterprise.mdb")
set rs=server.createobject("adodb.recordset")
Cnn.open StrCnn
sql="select distinct area1,area2 from company"
rs.open sql,cnn,1,1%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>

<body>
<form name="form1" method="post" action="results.asp">
<table width="100%" border="0" cellpadding="0" cellspacing="0" bordercolor="#000000" background="file:///d/enterprise/image.files/bg3.jpg">
<tr>
<td width="8%">编号:</td>
<td width="22%" bordercolor="#000000"><font size="2">
<input name="id" type="text" id="id" value="<%request.form("id")%>" size="6" maxlength="6">
</font></td>
<td width="36%" bordercolor="#000000"><font size="2"> 名称:
<input name="username" type="text" id="username" value="<%request.form("username")%>" size="20" maxlength="30">
</font></td>
<td width="11%">电话号码:</td>
<td width="23%"><input name="tel" type="text" id="tel" value="<%request.form("tel")%>" size="16" maxlength="11"></td>
</tr>
<tr>
<td>城市:</td>
<td bordercolor="#000000"><select name="area1" id="area1" size="1">
<option>城市</option>
<% do while not rs.eof%>
<option value="<%=rs("area1")%>" selected <%if request.form("area1")=rs("area1") then
response.Write("selected")
end if%> ><%=rs("area1") %></option>
<%rs.movenext
loop%>
</select> </td>
<td bordercolor="#000000">县/地区:
<select name="area2" size="1" id="area2">
<option selected>县城</option>
<% do while not rs.eof%>
<option value="<%rs("area2")%>"><%rs("area2")%></option>
<%rs.movenext
loop%>
</select> </td>
<td colspan="2">所属路段:<font size="2">
<input name="area3" type="text" id="area3" value="<%request.form("area3")%>" size="16" maxlength="16">
</font></td>
</tr>
<tr>
<td colspan="3">所属行业:<font size="2">
<SELECT name=kind1 id="kind1">
<option selected>所属行业</option>
<% do while not rs.eof%>
<option value="<%rs("sort1")%>"><%rs("sort1") %></option>
</SELECT>
<%rs.movenext
loop
%>
</font> </td>
<td colspan="2">输入关键字:
<input name="key" type="text" id="key" value="<%request.form("key")%>" size="16"></td>
</tr>
<tr>
<td height="20" colspan="3"> </td>
<td colspan="2"> <div align="center">
<input type="submit" name="Submit" value="搜索" >
</div></td>
</tr>
</table>
</form>
</body>
</html>
<%rs.close
set rs=nothing
cnn.close
set cnn=nothing %>
...全文
53 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
超级大笨狼 2003-12-07
  • 打赏
  • 举报
回复
我马上要升两星了,还差一百分,估计是明天
升完后我也要忙工作了
不能再沉迷在这里了
哎,舍不得这里给我这样的快乐和成就感!
今天拼命做了一个四级连动完美版,access数据库,速度非常快!!!
两个小文件总共代码一共不超过80行!9万条记录运行如飞!!
哈哈,终于完成,我做的
http://expert.csdn.net/Expert/topic/2537/2537402.xml?temp=.5528223
Han_YuBingXue 2003-10-02
  • 打赏
  • 举报
回复
数据库联动的例程在CSDN 就有啊,而且比你现在用的强去找找就可以了。
redrainy 2003-09-30
  • 打赏
  • 举报
回复
大家帮忙呀
redrainy 2003-09-30
  • 打赏
  • 举报
回复
大家帮帮我呀.我已经昨天一天在弄这个问题拉
redrainy 2003-09-30
  • 打赏
  • 举报
回复
我检查拉.我现在检查一下那几个地方<select>要放在do while 前面</select>要放在loop 后面。
没有错呀.但是测试还是老问题.
whyslr 2003-09-30
  • 打赏
  • 举报
回复
这个不是数据库方面的问题。而是html标志与循环之间的问题。你从新检查一下那几个地方<select>要放在do while 前面</select>要放在loop 后面。
redrainy 2003-09-30
  • 打赏
  • 举报
回复
数据库没有连错,因为在城市那个下拉列表框可以从数据库读出数据,并显示出来
redrainy 2003-09-30
  • 打赏
  • 举报
回复
哦,刚才粗心,没有完全按照要求写,现在是拉.但是还是rs2.close缺少对象,是怎么回事呢?

<td bordercolor="#000000">县/地区:
<%if request("area1")<>"" then
set rs2=server.createobject("adodb.recordset")
rs2.open "select distinct area2 from company where area1='"&request("area1")&"'",conn,1,1
if not rs2.eof then%>
<select name="area2" size="1" id="area2">
<option selected>县城</option>
<% do while not rs2.eof%>
<option value="<%rs2("area2")%>"><%rs2("area2")%></option>
<%rs2.movenext
loop%>
</select>
<%end if
end if
rs2.close
set rs2=nothing%>
</td>
redrainy 2003-09-30
  • 打赏
  • 举报
回复
现在是这样,<td bordercolor="#000000">县/地区:

<%if request("area1")<>"" then
set rs2=server.createobject("adodb.recordset")
rs2.open "select distinct area2 from company where area1='"&request("area1")&"'",conn,1,1%>

<select name="area2" size="1" id="area2">

<option selected>县城</option>
<% do while not rs2.eof%>
<option value="<%rs2("area2")%>"><%rs2("area2")%></option>
<%rs2.movenext
loop%>
</select>
<%end if
rs2.close
set rs2=nothing%>
</td>

但是:rs2.close
set rs2=nothing%>说是缺少对象,是怎么回事呢?
zjg791015 2003-09-30
  • 打赏
  • 举报
回复
数据库连接错误,没连接上数据库而又不报错。
海鸥 2003-09-30
  • 打赏
  • 举报
回复
把市名称的下拉框改成:
<select name="area1" id="area1" size="1" onChange="location.href='当前文件名.asp?area1='+this.value">
<option>城市</option>
<% do while not rs.eof%>
<option value="<%=rs("area1")%>" selected <%if request.form("area1")=rs("area1") then
response.Write("selected")
end if%> ><%=rs("area1") %></option>
<%rs.movenext
loop%>
</select>

县城的改为:
<%if request("area1")<>"" then
set rs2=server.createobject("adodb.recordset")
rs2.open "select distinct area2 from company where area1='"&request("area1")&"'",conn,1,1
if not rs2.eof then
<select name="area2" size="1" id="area2">

<option selected>县城</option>
<% do while not rs2.eof%>
<option value="<%rs2("area2")%>"><%rs2("area2")%></option>
<%rs2.movenext
loop%>
</select>
<%end if
end if
rs2.close:set rs2=nothing%>
ttt2 2003-09-30
  • 打赏
  • 举报
回复
<html>

<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建网页 1</title>
</head>
<%
xqid=request.querystring("xqid")
lid=request.querystring("lid")

set cn=server.createobject("adodb.connection")
cn.open "driver={sql server};uid=sa;pwd=abc;server=zhao;database=test"
set rs=server.createobject("adodb.recordset")
rs.open "select * from w_xq",cn,1,3

set rsl=server.createobject("adodb.recordset")

%>
<script language="javascript">

function s()
{

document.form1.lid.options[1]=null
document.form1.lid.options[0]=null
}


function changel(a)
{
if(a==0)
{
//alert("0")
return false
}


for(i=document.form1.lid.options.length-1;i>=0;i--)
{
document.form1.lid.options[i]=null
}

switch(a)
{
<%
while not rs.eof
%>
case "<%=rs("id")%>":
document.form1.lid.options[document.form1.lid.options.length]=new Option("---请选择---","0")
<%
rsl.open "select * from w_l where xqid="&rs("id"),cn,1,3
while not rsl.eof
%>

document.form1.lid.options[document.form1.lid.options.length]=new Option("<%=rsl("name")%>","<%=rsl("id")%>")
<%if lid<>"" and cint(lid)=rsl("id") then
%>
document.form1.lid.options.selectedIndex=document.form1.lid.options.length-1
<%end if%>
<%
rsl.movenext
wend
rsl.close
%>

break;
<%
rs.movenext
wend
%>

}



}



function changef(a,b)
{
if (b==0)
{
return false
}
location.href="index.asp?xqid="+a+"&lid="+b
}


</script>
<body>
<form name="form1" method="post" target=_blank action="select.asp">
<select name="xqid" onchange="changel(this.value)">
<option value="0">---请选择---</option>
<%
rs.movefirst
while not rs.eof
%>
<option value="<%=rs("id")%>" <%if cint(xqid)=rs("id") then%>selected<%end if%>><%=rs("name")%></option>
<%
rs.movenext
wend
%>
</select>
<!--onchange="changef(document.form1.xqid.value,this.value)"-->
<select name="lid" >
<option value="0">---请选择---</option>
</select> <input type="button" value="清除" name="B1" onclick="s()">
<input type="submit" value="提交" name="B2"></form>
<%
if xqid<>"" then
%>
<script language="javascript">
changel('<%=xqid%>')
</script>
<%end if%>
</body>

</html>
redrainy 2003-09-30
  • 打赏
  • 举报
回复
我很奇怪,为什么在测试的时候又没有报错,但是又无法正常显示呢?

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧