首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > ASP >

ASP读取数据库有关问题

2012-09-03 
ASP读取数据库问题,求助下边程序是一个考勤的代码,员工用账号登录系统后可以查看自己的考勤数据,现在有一

ASP读取数据库问题,求助
下边程序是一个考勤的代码,员工用账号登录系统后可以查看自己的考勤数据,现在有一个问题就是以下只能显示最新月份(time)的其中一条信息,而考勤每个月会有很多条记录,其他的数据就显示不出来,请教行家,应该怎么修改呀?
想要的效果:员工根据自己的卡号登录系统可以查询自己每个月的所有考勤记录,如果选择1205月就出现1205月所有的数据记录,求帮忙,谢谢。


ASP源代码

JScript code
</style></head><script language="javascript"><!--function CheckForm(){    if(document.form1.select.value=="0")    {        alert("请输入查询时间!");        document.form1.select.focus();        return false;    }                }--></script><body><%   if request("act")="xg" then  date_cx = request("select")  sql="select * from kq where time=#"&date_cx&"# and name='"&session("name")&"' order by time desc"  'response.write  sql  else  sql="select top 1 * from kq where  name='"&session("name")&"' order by time desc"  end if  set rs=server.CreateObject("adodb.recordset")  rs.open sql,conn,1,1  if rs.bof and rs.eof then  response.write "<script>alert('没有你的考勤表!');location.href='index.asp';</script>"  else  %><form id="form1" name="form1" method="post" action="grgzcx.asp?act=xg" onSubmit="return CheckForm();">  <label>  <select name="select" size="1">  <option value="0" >请选择查询时间</option>     <% dim char(20)         i=0        see=0        sql="select * from kq"        set time_rs=server.CreateObject("adodb.recordset")        time_rs.open sql,conn,1,1        do while Not time_rs.EOF                 for j=0 to i                 if char(j) = month(time_rs("time")) then                   see=1                   exit for                  else                   see = 0                  end if                  next                  if see=0 then          char(i)=month(time_rs("time"))             %>    <option value="<%=time_rs("time")%>"><%=time_rs("time")%></option>    <%        'char(i)=time_rs("time")      i=i+1      end if      time_rs.movenext      loop      time_rs.close      set time_rs = nothing     %>    </select>  </label>   <input type="submit" name="Submit" value="查询" />  <input type="reset" name="Submit2" value="重置" />  </form><table width="1153" border="1" cellspacing="0" cellpadding="2"  bordercolor="#CCCCCC" style="border-collapse:collapse">    <tr><td colspan="19">     <p align="left">font size="3"><b>主考勤表</b><font color="#FF0000</font></font></td></tr>    <tr>    <td width="50" align="center"><b><font size="2">岗位</font></b></td>    <td width="70" align="center"><b><font size="2">出勤日期 </font></b></td>    <td width="50" align="center"><b><font size="2">状态</font></b></td>    <td width="50" align="center"><b><font size="2">班制</font></b></td>    <td width="60" align="center"><b><font size="2">上班一</font></b></td>    <td width="60" align="right"><b><font size="2">下班一</font></b></td>    <td width="60" align="right"><b><font size="2">上班二</font></b></td>    <td width="60" align="right"><b><font size="2">下班二</font></b></td>    <td width="60" align="right"><b><font size="2">上班三</font></b></td>    <td width="60" align="right"><b><font size="2">下班三</font></b></td>    <td width="60" align="right"><b><font size="2">加班上</font></b></td>    <td width="60" align="right"><b><font size="2">加班下</font></b></td>    <td width="70" align="right"><b><font size="2">加班分钟</font></b></td>    <td width="70" align="right"><b><font size="2">出勤分钟</font></b></td>    <td width="70" align="right"><b><font size="2">出勤小时</font></b></td>    </tr>  <tr>  <%    i=2 Do While  i<rs.Fields.Count-5    %>   <td align="center" ><%= rs(i)%></td>   <% i=i+1   loop   %>    <%   rs.closeset rs=nothing      %>     </tr><%end if %></body></html> 



[解决办法]
sql="select top 1 * from kq where name='"&session("name")&"' order by time desc"
你这行代码决定只显示1条

应该改为:
sql="select * from kq where name='"&session("name")&"' order by time desc"

[解决办法]
后面 加 一个 1=1 看看

热点排行