带参数的 sub() 如何使用?
在写 代码时,经常会重复写到 select / update 的 同类语句,重复性比较多。能否给 SUB 代些 参数进去执行相同的操作。
然后代参数调用?我写了如下代码,但是调用时,浏览器没有提示出错,但页面却是一片空白,什么也没有(数据库中是有数据可用的),不知道是什么原因。请大家指教下和纠正错误的地方,谢谢!
如
tablename 为 表名参数 ,ziduan 为 查询字段参数,rs_where 为 条件参数,rs_by 为排序参数
sub dataList (tablename,ziduan,rs_where,rs_by)
sql="select "&ziduan&" from "&tablename&" where "&rs_where&" order by "&rs_by&" "
set rs=conn.execute(sql)
if rs.bof and rs.eof then
response.write "查无数据"
rs.close
set rs=nothing
else
do while not rs.eof
response.write rs(0)&" "&rs(1)
rs.movenext
loop
rs.close
set rs=nothing
end if
end sub
[color=Red]在调用的地方call dataList (表名,字段,条件,排序)[/color]
我的调用如下
<%
dim str
str="id,class_cn"
strs="tt=1"
px="px desc"
call prolist(category,str,strs,px)
%>
终于纠正,搞掂!贴出来,分享下!早就懂的朋友请勿见笑
<%sub prolist(str_table,str_select,str_where,str_by)
sql="select "&str_select&" from "&str_table&" where "&str_where&" order by "&str_by&" "
set rs=conn.execute(sql)
if rs.bof and rs.eof then
response.Write("程序编写错误")
else
do while not rs.eof
response.Write "名称:"&rs(0)&" "&"说明"&rs(1)
rs.movenext
loop
end if
end sub
%>
<%call prolist("category","id,class_cn","tt=1","px desc")%> 好人! 楼主好人,呵呵,又学了一招!调用好方便! 很好地实现了代码复用。值得提倡。
页:
[1]
