搜索用不了回车键,大家看看,用变量定义。

xfxq 2003-08-25 09:43:43
错误如下:
Microsoft OLE DB Provider for SQL Server 错误 '80040e14'
在关键字 'ORDER' 附近有语法错误。

detail.asp,行101

主要代码如下:

<form name="form1" method="get" actiondetail.asp">
<table width="100%" border="0" cellspacing="0" height="40">
<tr valign="top">
<td width="427" valign="bottom" height="15">  请输入名字:
<input type="text" name="Name" size="30">
</td>
<td width="164" valign="bottom" height="15">
<input type="submit" name="UseFind" value="查询">
</td>
</tr>
</table>
</form>

<%'不同方式进入此页,查询语句不同
if strUseFind <> "" then '使用查询方式
strSql = "SELECT * FROM NYan WHERE YName LIKE '%" & strYName & "%'"
if strYName <> "" then
strSql = strSql & " AND YName LIKE '%" & strYName & "%'"
end if
strSql = strSql
else '直接进入方式
strSql = "SELECT * FROM NYan WHERE "
strSql = strSql
end if
strSql = strSql & " ORDER BY ID DESC"
rs.Open strSql, Conn, 3, 1
%>

请各位指教了,如何敲回车键也可以进行查询,谢谢。
...全文
87 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
windancer 2003-09-02
  • 打赏
  • 举报
回复
strUseFind = UCase(CStr(Request("UseFind")))
if strUseFind <> "" then
strYName = CStr(Request("YName"))
strYID = CStr(Request("YID"))
end if
改成
if request.ServerVariables("REQUEST_METHOD")="POST" then
strYName = CStr(Request("YName"))
strYID = CStr(Request("YID"))
end if
Keyln 2003-09-02
  • 打赏
  • 举报
回复
你這樣做肯定是的呀。。。
post 并沒有取到text的值。
xfxq 2003-09-02
  • 打赏
  • 举报
回复
to windancer(风精灵)
if strUseFind <> "" then '使用查询方式
strSql = "SELECT * FROM NYan WHERE YName LIKE '%" & strYName & "%'"
if strYName <> "" then
strSql = strSql & " AND YName LIKE '%" & strYName & "%'"
end if
strSql = strSql
else '直接进入方式
strSql = "SELECT * FROM NYan WHERE "//这两句是否有错
strSql = strSql //??
end if
strSql = strSql & " ORDER BY ID DESC"


如为空查询的话,那么strSql="SELECT * FROM NYan WHERE ORDER BY ID DESC"//肯定错

现在我加上条件,
else '直接进入方式
strSql = "SELECT * FROM NYan WHERE YName LIKE '%" & strYName & "%'"
strSql = strSql
这样用回车倒是可以,但如果输入条件,用回车后出来的结果又是全部的东西,没有按条件找,请问如何解决,谢谢!
windancer 2003-08-25
  • 打赏
  • 举报
回复
if strUseFind <> "" then '使用查询方式
strSql = "SELECT * FROM NYan WHERE YName LIKE '%" & strYName & "%'"
if strYName <> "" then
strSql = strSql & " AND YName LIKE '%" & strYName & "%'"
end if
strSql = strSql
else '直接进入方式
strSql = "SELECT * FROM NYan WHERE "//这两句是否有错
strSql = strSql //??
end if
strSql = strSql & " ORDER BY ID DESC"


如为空查询的话,那么strSql="SELECT * FROM NYan WHERE ORDER BY ID DESC"//肯定错
xfxq 2003-08-25
  • 打赏
  • 举报
回复
<!--#INCLUDE virtual="/include/conn.asp" -->
<!--#INCLUDE virtual="/include/func.asp" -->
<%
'变量定义和初始化
const vbNoPerPage = 20
dim rs
dim intCount, intStartPos, intShowCount, blNoNextPage, strHref ,strUseFind , strColor
dim strYName, strYID
dim intNowPage

strUseFind = UCase(CStr(Request("UseFind")))
if strUseFind <> "" then
strYName = CStr(Request("YName"))
strYID = CStr(Request("YID"))
end if
intNowPage = CInt(Request("Page"))
if intNowPage < 1 then
intNowPage = 1
end if
intStartPos = (intNowPage - 1) * vbNoPerPage
blNoNextpage = false
strSql = ""

%>
<html>
<head>
<title>产品列表</title>
<link rel="stylesheet" href="/css/memo.css" type="text/css">
<link rel="stylesheet" href="/css/link.css" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language="JavaScript">
function sd(vurl) {
var vhrf;
if (! window.focus) return true;
if (typeof(vurl) == 'string')
vhrf=vurl;
else
vhrf=vurl.href;
window.open(vhrf, "", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=650,height=300,left=50,top=0");
return false;
}
</script>
</head>
<!--#include virtual="/include/nomk.asp" -->
<div align="center">
<!--#include virtual="/include/head1.asp" -->
<table width="780" border="0" cellspacing="0" background="/imagenew/indexxxxw/indexxxxw_r9_c3.gif">
<tr>
<td>
<table width="780" border="0" cellspacing="0" height="80">
<tr>
<td bgcolor="#97DD85" background="/imagenew/indexxxxw/indexxxxw_r2_c5.gif" height="25" width="780"><font color="#CCFFFF"><b><font color="#000000" size="2">  产品查询</font></b></font></td>
</tr>
<tr>
<td align=center height="40" valign="middle" width="755">
<form name="form1" method="post" action="/threenew/newscp/detail.asp">
<table width="100%" border="0" cellspacing="0" height="40">
<tr valign="top">
<td width="427" valign="bottom" height="15">  请输入名称:
<input type="text" name="YName" size="30">
</td>
<td width="164" valign="bottom" height="15">
<input type="submit" name="UseFind" value="查询">
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</td>
</tr>
</table>
<table width="782" border="0" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td width="81" align=center height="35"><b>序号</b></td>
<td align=center height="35" width="290"><b>名称</b></td>
<td align=center height="35" width="379"> </td>
</tr>
<%
set rs = Server.CreateObject("ADODB.Recordset")

'不同方式进入此页,查询语句不同
if strUseFind <> "" then '使用查询方式
strSql = "SELECT * FROM NYan WHERE YName LIKE '%" & strYName & "%'"
if strYName <> "" then
strSql = strSql & " AND YName LIKE '%" & strYName & "%'"
end if
strSql = strSql
else '直接进入方式
strSql = "SELECT * FROM NYan WHERE "
strSql = strSql
end if

strSql = strSql & " ORDER BY ID DESC"
rs.Open strSql, Conn, 3, 3

'转到指定的页数
for intCount = 1 to intStartPos
if rs.Eof then
Exit For
end if
rs.MoveNext
next

intShowCount = vbNoPerPage
if intStartPos + vbNoPerPage >= rs.RecordCount then
intShowCount = rs.RecordCount - intStartPos
blNoNextPage = true
end if

'显示纪录
'for intCount = 1 to intShowCount
for intCount = 1 to vbNoPerPage
if intCount mod 2 = 0 then
%>
<tr>
<%
else
%>
<tr>
<%
end if
if rs.Eof then
' Exit For
%>
<td width="81"> </td>
<td colspan="2"> </td>
</tr>
<%
else
%>
<td width="81" align=center>
<% = intStartPos + intCount%>
</td>
<td colspan="2"><a href="/threenew/newscp/<% = rs("YID") %>.asp" target="_blank" onClick="return sd(this);">
<% = rs("YName") %>
</a><b><font color=<% = strColor %>> </font></b> </td>
</tr>
<%
rs.MoveNext
end if
next
%>
</table>
<table width="780" border="0" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td colspan="2">
<hr color="#97DD85">
</td>
</tr>
<tr>
<td>共有
<% = rs.RecordCount %>
条记录.(
<% = intStartPos + 1%>
-
<% = intStartPos + intShowCount%>
)</td>
<td align=right>
<%
if intNowPage > 1 then
strHref = "detail.asp?UseFind=" & strUseFind & "&YName=" & strYName & "&Page=" & (intNowPage - 1)%>
<a href=<% = strHref %>>上一页</a>
<%
end if
if not blNoNextPage then
strHref = "detail.asp?UseFind=" & strUseFind & "&YName=" & strYName & "&Page=" & (intNowPage + 1)
%>
<a href=<% = strHref %>>下一页</a>
<%
end if
%>
</td>
</tr>
<tr>
<td height="20"> </td>
<td align=right height="20"> </td>
</tr>
</table>
<%
rs.Close

set rs = nothing
%>
<!--#include virtual="/include/bottom1.asp" -->
</div>
</body>
</html>
<!--#INCLUDE virtual="/include/free.asp" -->
stefli 2003-08-25
  • 打赏
  • 举报
回复
<input type="text" name="Name" size="30">
<script for=Name event=onkeydown>
<!--
if(window.event.keyCode==13)
{
document.all.form1.submit();
}
//-->
</script>
Gorgee 2003-08-25
  • 打赏
  • 举报
回复
应该是某些特殊码传入,你可以自己显示下每个变量的最后字符的asc码
do while asc(right(strSql,1))=0
strSql=left(strSql,len(strSql)-1)
loop
strSql = strSql & " ORDER BY ID DESC"
windancer 2003-08-25
  • 打赏
  • 举报
回复
估计是少了空格或者sql语句动态组织不完整
windancer 2003-08-25
  • 打赏
  • 举报
回复
这种问题只要把回车时的strSql 值response.write一下看看就知道了
xfxq 2003-08-25
  • 打赏
  • 举报
回复
也不行的了,呵呵。
Gorgee 2003-08-25
  • 打赏
  • 举报
回复

strSql = strSql & " ORDER BY ID DESC"
在这之前处理下strSql字符串
do while asc(right(strSql,1))=0
strSql=left(strSql,len(strSql)-1)
loop
xfxq 2003-08-25
  • 打赏
  • 举报
回复
用post也不行的,我早就试过了,

sql语句应该没有错的,我点击搜索出来的结果是对的,只是用回车不行。
出错信息的行为:
rs.Open strSql, Conn, 3, 1
大家看看有什么解决方法啊。
全息宇宙 2003-08-25
  • 打赏
  • 举报
回复
一定是sql语句有错误,输出来看看:

<%'不同方式进入此页,查询语句不同
on error resume next

if strUseFind <> "" then '使用查询方式
strSql = "SELECT * FROM NYan WHERE YName LIKE '%" & strYName & "%'"
if strYName <> "" then
strSql = strSql & " AND YName LIKE '%" & strYName & "%'"
end if
strSql = strSql
else '直接进入方式
strSql = "SELECT * FROM NYan WHERE "
strSql = strSql
end if
strSql = strSql & " ORDER BY ID DESC"
rs.Open strSql, Conn, 3, 1

response.write sql ''输出来看看
%>
  • 打赏
  • 举报
回复
method="post"
xfxq 2003-08-25
  • 打赏
  • 举报
回复
<form name="form1" method="get" action="detail.asp">
刚才拷的时候少了一个加号。

28,390

社区成员

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

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