工大后院

 找回密码
 加入后院

扫一扫,访问微社区

QQ登录

只需一步,快速开始

搜索
查看: 4671|回复: 66

请教一下asp

[复制链接]
发表于 2007-4-1 16:36 | 显示全部楼层 |阅读模式
<META c>
<%@ codepage ="936" %>
<!--#include file="session.asp" -->
<!--#include file="dbconn.asp" -->
<link rel="stylesheet" type="text/css" href="style.css"><body bgcolor="#FFFFFF" marginheight=0 marginwidth=0 leftmargin=0>
<script language="javascript">
function job(mylink)
{
window.open(mylink,'','top=150,left=120,width=440,height=500,scrollbars=yes')
}
</script>
<%
'查询到的所有的记录数
dim totalPut
'显示的当前页面数
dim CurrentPage
'共分多少页显示
dim TotalPages
'每页显示多少条记录
dim MaxPerPage
'初始设置为4
MaxPerPage=10
'中间的循环变量
dim i,j
'判断如果没有输入页面数,则显示第1个页面
if not isempty(request("page")) then
   currentPage=cint(request("page"))
else
   currentPage=1
end if
'定义的记录集对象
dim rs
'sql命令
dim sql
set rs=server.createobject("adodb.recordset")
'生成sql命令
typeid=request("typeid")
if typeid="" then
   sql="Select * From law order by no desc"
else
   sql="select * from law where "
   sql=sql&cstr(typeid)&" like '%"&request("txtitle")&"%' "
   sql=sql&" order by no desc"
end if
'生成记录集
rs.open sql,conn,1,1
'判断是否有记录
if rs.eof and rs.bof then
response.write "<p align='center'>对不起,没有您要查找的信息</p>"
else
   '如果有符合条件的记录,则将符合条件的记录总数值赋给变量totalPut
   totalPut=rs.recordcount
   '分页判断,如果当前页面数小于1,则更改为1
   if currentpage<1 then
      currentpage=1
   end if

   if (currentpage-1)*MaxPerPage>totalput then
      if (totalPut mod MaxPerPage)=0 then
         currentpage= totalPut \ MaxPerPage
      else
         currentpage= totalPut \ MaxPerPage + 1
      end if
   end if
  '如果当前页数为1,则调用过程showcontent、函数showpage显示
  if currentPage=1 then
     showContent
     showpage totalput,MaxPerPage,"default.asp"
  else
    '如果当前页数为其他页,则使用书签bookmark来定位后调用过程showcontent、函数showpage显示
if (currentPage-1)*MaxPerPage<totalPut then
       rs.move (currentPage-1)*MaxPerPage
       dim bookmark
       bookmark=rs.bookmark
       showContent
       showpage totalput,MaxPerPage,"default.asp"
    else
       currentPage=1
       showContent
       showpage totalput,MaxPerPage,"default.asp"
    end if
  end if
  rs.close
end if
set rs=nothing
'定义过程SubContent,显示搜索表单
sub showContent
%>
<center>
<TABLE border=0 cellPadding=3 cellSpacing=0 width="600" style="border-collapse: collapse" bordercolor="#111111">
<TBODY>
<TR bgcolor="#ffffcc">
<TD align=left bgcolor="#FFFFFF">
<form name="search" method="post" action="default.asp">
  <p align="center">
  <img src="images/search.gif"> 默认以案件编号搜索:
  <input type="text" name="txtitle" size="25" style="font-size: 9pt">  
  <select style="font-size: 9pt" name="typeid">
   <option value="no">案件编号</option>
   <option value="date">日期</option>
   <option value="topic">文档标题</option>
   <option value="people">办案人</option>
   <option value="note">备注</option>
   </select>
   <INPUT align=absMiddle border=0 src="images/search1.gif" type=image name="I2">

</form>
<p> </p>
<CENTER>
   <TABLE border="1" cellspacing="0" width="574" cellpadding="4" style="border-collapse: collapse" bordercolor="#111111" bordercolorlight="#A6D2FF" bordercolordark="#A6D2FF">
   <TR height=25 bgcolor="#cccccc">
    <TD width="63" align="center" bgcolor="#CEE8FF"><font color="ff6600"><b>案件编号</b></font></td>
    <TD width="62" align="center" bgcolor="#CEE8FF"><strong><font color="ff6600">办案日期</font></strong></td>
    <TD width="68" align="center" bgcolor="#CEE8FF"><strong><font color="#FF6600">办案人</font></strong></td>
    <TD width="67" align="center" bgcolor="#CEE8FF"><strong><font color="ff6600">备注</font></strong></td>
    <TD width="48" align="center" bgcolor="#CEE8FF"><font color="#Ff6600"><b>修改</b></TD>
    <TD width="48" align="center" bgcolor="#CEE8FF"><font color="#Ff6600"><b>删除</b></TD>
    <TD width="146" align="center" bgcolor="#CEE8FF"><font color="#Ff6600"><b>录入</b></TD>
   </TR>
<%do while not rs.eof%>
   <TR height="20" bgcolor="#ffffff">
     <TD width="63" align="left"><font face="Arial"><b><%=rs("no")%></b></font> </td>
     <TD width="62"><a href="javascript:job("SELECT.ASP?no=<%=rs("no")%>")"><font color="#FF6600"><%=rs("date")%></font></a></td>
     <TD width="63" align="left"><font face="Arial"><b><%=rs("people")%></b></font> </td>
     <TD width="63" align="left"><font face="Arial"><b><%=rs("note")%></b></font> </td>
     <TD width="48" align="center"><a href="UPDATE.ASP?no=<%=rs("no")%>"><img src="images/edit.gif" alt="修改信息" width="18" height="18" border="0"></a></TD>
     <TD width="48" align="center"><a href="DELETE.ASP?no=<%=rs("no")%>"><img src="images/delete.gif" alt="删除信息" width="18" height="17" border="0"></a></td>
     <TD width="146" align="center"><a href="INSERT.ASP"><img src="images/add.gif" alt="录入信息" width="16" height="16" border="0"></a></td>
   </TR>
<%i=i+1
  IF i>=MaxPerPage then exit do
  rs.movenext
  loop
%>
</TABLE>
</center>
<%
end sub
'定义函数showPage
function showpage(totalnumber,maxperpage,filename)
dim n
if totalnumber mod maxperpage=0 then
    n= totalnumber \ maxperpage
else
    n= totalnumber \ maxperpage+1
end if
if CurrentPage<2 then
   response.write "<table border=0 width=600 cellspacing=0 cellpadding=0>"
   response.write "<tr height=30>"
   response.write "<td align=left>"
   response.write "共<font color=ff6600><b>"&n&"</b></font>页 第<font color=ff6600><b>"&CurrentPage&"</b></font>页 共检索到<font color=ff6600><b>"&totalnumber&"</b></font>条信息</TD>"
   response.write "<td align=right>"
   response.write "【最前页】【上一页】"
else
   response.write "<table border=0 width=600 cellspacing=0 cellpadding=0>"
   response.write "<tr height=30>"
   response.write "<td align=left>"
   response.write "共<font color=ff6600><b>"&n&"</b></font>页 第<font color=ff6600><b>"&CurrentPage&"</b></font>页 共检索到<font color=ff6600><b>"&totalnumber&"</b></font>条信息"
   response.write "<td align=right>"
   response.write "【<a href="&filename&"?page=1&typeid="&tyeid&"&txtitle="&request("txtitle")&">最前页</a>】"
   response.write "【<a href="&filename&"?page="&CurrentPage-1&"&typeid="&typeid&"&txtitle="&request("txtitle")&">上一页</a>】"
end if
if n-currentpage<1 then
   response.write "【下一页】【最后页】"
else
   response.write "【<a href="&filename&"?page="&(CurrentPage+1)&"&typeid="&typeid&"&txtitle="&request("txtitle")&">"
   response.write "下一页</a>】【<a href="&filename&"?page="&n&"&typeid="&typeid&"&txtitle="&request("txtitle")&">最后页</a>】"
end if
response.write "</td>"
response.write "</tr>"
response.write "</table>"
response.write "</form>"
end function
%>
</body>
</html>




是这样的,我用asp+access做了个查询网页,兼有录入/删除/修改的功能
开始用login.asp进行用户名验证
验证通过后跳到defult.asp,就是上面那个代码
defult前面有个session.asp是用来禁止直接访问defualt.asp的
就是不通过验证,直接在ie上访问default,就自动跳转到验证页面login.asp

问题就是改来改去,搞到现在正常登陆到dufault界面老说对不起,没有您要查找的信息
找了很久都不知道哪里出了小问题

ps:数据库名叫law,表名叫file
下面有几个字段:no=案件编号
date=日期
topic=文档标题
people=办案人
note=备注


麻烦高手帮忙看看
发表于 2007-4-1 17:03 | 显示全部楼层
sql="select * from law where "
   sql=sql&cstr(typeid)&" like '%"&request("txtitle")&"%' "
   sql=sql&" order by no desc"


这段好怪好怪...不知干嘛这么写...
回复

使用道具 举报

 楼主| 发表于 2007-4-1 17:11 | 显示全部楼层
你指这句?sql=sql&cstr(typeid)&" like '%"&request("txtitle")&"%' "

这句是说文档框txtitle+下拉选项typeid用于查询
然后按照no倒序列出

这个好像没问题的
我以前做的查询网页也是这样写的,可以
回复

使用道具 举报

发表于 2007-4-1 17:19 | 显示全部楼层
request("typeid")不为空的时候,查询数据库字段typeid like request("txtitle") 的记录?

如果这样的逻辑真的没错,那最好在我说很奇怪的那几句下面加上一句调试语句
response.write sql
response.end

看看会输出什么
回复

使用道具 举报

 楼主| 发表于 2007-4-1 17:21 | 显示全部楼层
thx,try
回复

使用道具 举报

 楼主| 发表于 2007-4-1 17:27 | 显示全部楼层
没反应,还是那几句话
回复

使用道具 举报

 楼主| 发表于 2007-4-1 17:38 | 显示全部楼层
我看了typeid的属性初始值是没选定的
要是选定了而且文本框没有数据才可能说没有查询数据啊
还没弄明白
回复

使用道具 举报

发表于 2007-4-1 17:45 | 显示全部楼层
加了我那两句话还是提示“对不起,没有您要查找的信息”?

那表示request("typeid")为空?
回复

使用道具 举报

 楼主| 发表于 2007-4-1 17:54 | 显示全部楼层
response.write sql
什么意思啊?是不是typeid有值就输出sql语句?
还是提示那句话哦
那是不是说request("typeid")为空
回复

使用道具 举报

发表于 2007-4-1 18:16 | 显示全部楼层
response.write sql就是输出你那个sql语句

response.end中止程序的执行

所以如果你的asp会经过这段语句的话,那语句以下的所有程序都不会继续执行下去的啦,也不可能会出来那个提示


出来那个提示,说明程序根本没有经过response.end

再看看前面的if语句,应该是request("typeid")为空


asp查错,都是如此类似的
用同样方法也可以检查一下,request("typeid")是否真的为空
回复

使用道具 举报

 楼主| 发表于 2007-4-1 18:38 | 显示全部楼层
if typeid="" then
   sql="Select * From law order by no desc"
else
   sql="select * from law where "
   sql=sql&cstr(typeid)&" like '%"&request("txtitle")&"%' "
   sql=sql&" order by no desc"
end if


我认为不是这样哦
一般情况确实不会运行到
else
   sql="select * from law where "
   sql=sql&cstr(typeid)&" like '%"&request("txtitle")&"%' "
   sql=sql&" order by no desc"
这里
因为,默认typeid为空,执行完   sql="Select * From law order by no desc"就直接跳到end if后面去继续运行了

我在sql="Select * From law order by no desc"后面加了你给的两个语句也确实是这样
输出为Select * From law order by no desc



ps:学到了asp一些debug的技巧,很感谢

[ 本帖最后由 2002070344 于 2007-4-1 18:39 编辑 ]
回复

使用道具 举报

发表于 2007-4-1 19:13 | 显示全部楼层
request("typeid")原来是空的?我还以为你从上个页面post过来的 那就不用管那些啦


如果确定Select * From law order by no desc确实有值的话
那么就只能在”if rs.eof and rs.bof then“这句上找问题啦

虽然这句我也觉得没什么问题
但还是试试把
if rs.eof and rs.bof then
response.write "<p align='center'>对不起,没有您要查找的信息</p>"
else
........
end if

改成

if not rs.eof then
.......
else
response.write "<p align='center'>对不起,没有您要查找的信息</p>"
end if
回复

使用道具 举报

 楼主| 发表于 2007-4-1 19:27 | 显示全部楼层
好像知道哪里了
惭愧惭愧
好像我把select from这里的表名写成数据库名了
试试先
要是真这样真是
回复

使用道具 举报

 楼主| 发表于 2007-4-1 19:31 | 显示全部楼层
真是这样
我搞昏了,数据库名叫law,下面有两个表,一个是登陆密码name,一个是defult的数据file
不好意思,自己搞错了
谢谢
回复

使用道具 举报

发表于 2007-4-1 19:54 | 显示全部楼层
编程版难得的版聊帖~
回复

使用道具 举报

 楼主| 发表于 2007-4-1 20:42 | 显示全部楼层
菜鸟,见谅
回复

使用道具 举报

 楼主| 发表于 2007-4-2 10:42 | 显示全部楼层
再问一个菜鸟的问题
我在做update修改页面时
用sql="select * from file where no="&no来下载原先的档案准备等会修改
file是表名
no是表下的一个字段
&no是上一个链接过来的页面传递过来的参数
就是我点某个编号项,就链接到该编号的修改页
这个语句好像有点问题,不过我不是很懂sql语句
所以还是不知道错在哪里
这个还是抄以前运行的模板
就不知道怎么回事
后来换成
sql="select * from file where"
sql=sql&no
分两段来写就行了
麻烦指点一下
回复

使用道具 举报

 楼主| 发表于 2007-4-2 12:04 | 显示全部楼层
不过好像有问题
update加载的老是一个编号的数据
回复

使用道具 举报

发表于 2007-4-2 17:49 | 显示全部楼层
这样吧。。。
sql="select * from file where="
sql=sql&no

我觉得
sql="select * from file where no="&no
应该没有问题。。

刚才测试过了。。。没有问题。。
回复

使用道具 举报

 楼主| 发表于 2007-4-2 18:35 | 显示全部楼层
两个都不行哦,加载不到数据


<META c>
<[email=%@LANGUAGE=]%@LANGUAGE="VBSCRIPT[/email]" CODEPAGE="936"%>
<!--#include file="dbconn.asp" -->
<link rel="stylesheet" type="text/css" href="style.css">
<style type="text/css">
<!--
.STYLE1 {color: #FF0000}
-->
</style>
<body bgcolor="#FFFFFF" marginheight=0 marginwidth=0 leftmargin=0>
<html>
<head>
<meta http-equiv="Content-Type" c>
<title>修改编号<%=request("no")%>的记录</title>
<%
if not isEmpty(request("no")) then
     no=request("no")  
else
     no=1
end if
Set rs=Server.CreateObject("ADODB.Recordset")
sql="select * from file where no="&no

rs.open sql,conn,1,1
%>
<body>
<table width="380" border="0" align="center" cellpadding="0">
  <tr>
    <td><div align="center">修改编号<span class="STYLE1"><%=request("no")%></span>的记录</div></td>
  </tr>
</table>
<form action="SAVEUPDATE.asp?no=<%=rs("no")%> " method="post"" name="form1" target="_parent"post>
<table width="48%" height="310" border="2" align="center" bordercolor="#D4D0C8" id="AutoNumber1" style="border-collapse: collapse">
  
  <tr>
    <td width="100%" height="38"><span class=ap9x><font color="#000080"><span lang="zh-cn">日期</span>:</font></span>
      <label>
      <input name="txtdate" type="text" id="txtdate" value="<%=rs("date")%>">
      </label></td>
    </tr>
  <tr>
    <td height="33"><span class=ap9x><font color="#000080"><span lang="zh-cn">文档标题</span>:</font><font color="#FF0000">
      <input name="txttopic" type="text" id="txttopic" value="<%=rs("topic")%>" size="38">
    </font></span></td>
    </tr>
  <tr>
    <td height="33"><font color="#000080">经办人:</font>
      <input name="txtpeople" type="text" id="txtpeople" value="<%=rs("people")%>">
      <span class=ap9x> </span> </td>
    </tr>
  
  <tr>
  <td height="36"><span class=ap9x><font color="#000080">备注:</font></span></td>
  </tr>
<tr>
  <td><font color="#000080"><span class=ap9x><font color="#000080"><font color="#000080">
    <textarea name="txtnote" cols="60" rows="6" id="txtnote"><%=rs("note")%></textarea>
  </font><font color="#000080">
    <input type="submit" name="Submit" value="提交修改">
    </font></font></span></font></td>
  </tr>
</table>
  <p>     </p>
</form>
</body>
</html>

[ 本帖最后由 2002070344 于 2007-4-2 18:37 编辑 ]
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 加入后院

本版积分规则

QQ|Archiver|手机版|小黑屋|广告业务Q|工大后院 ( 粤ICP备10013660号 )

GMT+8, 2025-5-15 03:36

Powered by Discuz! X3.5

Copyright © 2001-2024 Tencent Cloud.

快速回复 返回顶部 返回列表