标题:请问如何把checkbox参数用作sql语句中的查询要求啊????
取消只看楼主
who_young
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2010-10-19
结帖率:50%
已结贴  问题点数:20 回复次数:0 
请问如何把checkbox参数用作sql语句中的查询要求啊????
想了很久没想出来...

这是前台代码,本想是通过checkbox把要分成一组的学生学号传递到后台,然后作为sql语句IN(...)的查询匹配条件,用的数据库是SQLSERVER2000的

但是checkbox传递过去的参数是字符串...比如 “1,5,9,6,87,...0” 这样

而数据库中的字段是int型,所以总是不匹配...

能把checkbox的参数全部变成int的啊?试过了Cint 不行...

然后试过了用数组还是不行...

哪位知道的朋友指点一下吧,小生感激不尽了!!
<form action="admin_array_check.asp" method="post">
                <input type="submit" value="分组">
                <table>
                    <tr>
                        <td>学号</td>
                        <td>学生姓名</td>
                    </tr>
                    <% do while not rs.eof %>
                    <tr>
                        <td><input type="checkbox" name="check" value="<%= rs("sid")%>"><%= rs("sn")%></td>
                        <td><%= rs("name")%></td>
                    </tr>
                    <%
                        rs.movenext
                        loop
                        
                        rs.close
                        set rs=nothing
                    %>
              </table>
 </form>




后台的代码:

<body>
    <%
        dim checknum
        checknum = request.Form("check")
        
        
        dim chk(9)
            for i=0 to UBound(split(checknum,","))
            chk(i)=Cint(split(checknum,",")(i))
        next
        
        
        
        set rs=Server.CreateObject("ADODB.Recordset")'有参数
        sql="select * from student where sid IN("&chk(0),chk(1),chk(2),chk(3),chk(4),chk(5)&")"
        rs.open sql,conn,2,3
    %>
    <div>
    <form action="admin_array_back.asp" method="post">
        请确认小组成员<br />
        <textarea name="members" rows="100">
            <%
                do while not rs.eof
                    
                    response.Write(rs("name"))

                rs.movenext
                loop
            %>
        </textarea>
        <br />
        请输入小组名称
        <br />
        <input type="text" name="group_name" />
        
        <input type="submit" value="确认分组">
        
    </form>
    </div>

</body>



搜索更多相关主题的帖子: 数据库 字符串 朋友 
2011-02-23 11:36



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-332648-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.109827 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved