asp详细查询excel中的数据.

nbzzw6688 2015-11-29 08:56:06
想做一个程序可以查询excel中的数据.
find.asp中代码是


<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>

<body>


<form action="index.asp" name="form">
<p>
<input type="text" id="name" name="name" />

</p>
<p> </p>
<p>
<input type="submit" name="submit" id="submit" value="提交">

</p>
<p> </p>
</form>
</body>
</html>




结果页index.asp代码是


<!doctype html>
<html>
<head>
<meta charset="gb2312">
<meta http-equiv="refresh" content="10" />
<title>无标题文档</title>

</head>
<!--#include file="conn.asp"-->
<%
Dim conn
Dim StrConn
Dim rs
Dim Sql
Set conn=Server.CreateObject("ADODB.Connection")
StrConn="Driver={Microsoft Excel Driver (*.xls)};DBQ="& Server.MapPath("database\list.xls")
conn.Open StrConn
Set rs = Server.CreateObject("ADODB.Recordset")
Sql="select * from [Sheet1$] where name like '"&name&"'"
rs.Open Sql,conn,2,2
%>
<center>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<%
for i=0 to rs.Fields.Count-1
%>
<td width="1" bgcolor="#CCCCCC"></td>
<td height="28" bgcolor="#0099FF"><div align="center"><%=rs(i).Name%></div></td>
<%
next
%>
<td width="1" bgcolor="#CCCCCC"></td>
</tr>
<%
do while Not rs.EOF
%>
<tr>
<%
for i=0 to rs.Fields.Count-1
%>
<td width="1" bgcolor="#CCCCCC"></td>
<td height="28" valign="bottom"><%=rs(i)%></td>
<%
next
%>
<td width="1" bgcolor="#CCCCCC"></td>
</tr>
<tr>
<%
for i=0 to rs.Fields.Count-1
%>
<td height="1" bgcolor="#CCCCCC"></td>
<td height="1" bgcolor="#CCCCCC"></td>
<%
next
%>
<td width="1" bgcolor="#CCCCCC"></td>
</tr>
<%
rs.MoveNext
Loop
rs.close
set rs=nothing
Conn.close
set StrConn=nothing
%>
</table>
</center>
</body>
</html>


想实现填入查询d12点find.asp中的提交按钮转到index.asp,查询出结果.但是一直没有查询出结果.如果直接改sql语句 Sql="select * from [Sheet1$] where name like 'd12'"却可以查询出name为d12的所有结果.
问大家一下问题出在哪里?要怎么改?
...全文
116 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
nbzzw 2015-11-30
  • 打赏
  • 举报
回复
结果页,变量未定义。定义变量看看。

28,391

社区成员

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

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