ASP中的VBscript种种用法

1、转换时间类型:

< % = datevalue (rs( " fbsj " ))% >
上面的代码中rs("fbsj")从数据库存中取得的时间字段值,它是长时间类型的
使用datavalue(rs("fbsj"))进行转换!

2、取字符串中的字符操作
 一、从字符串左边取出2个字符:
1  dim  stra
2  stra  = " welcome "
3  stra = left (stra, 2 )
4  response.write(stra)
二、从字符串右边取出3个字符:
1  dim  stab
2  strb = " come on baby "
3  strb = right (strb, 3 )
4  response.write(strb)

3、删除数据:
1 < %
2 If  Request( " Action " ) = " Del "   Then
3     Conn.Execute( " Delete From dwzp Where did= " & Request.querystring( " did " ))
4     Response.Redirect  " zhaopingManager.asp?cid= " & request.querystring( " cid " )
5     response.end
6 End   If
7 % >
4、将数据库的值填充至table的做法:
< %
cid
= request.QueryString( " cid " )
set  rs = server.CreateObject( " adodb.recordset " )
strsql
= " select * from dwzp where cid= " & cid
rs.open strsql,conn,
1 , 3

%
>
< table width = " 600px "  border = " 0 "  cellspacing = " 0 "  cellpadding = " 0 " >
< tr class = " trtitle " >
< td width = " 120px " >
招骋职位
</ td >

< td >
性别要求
</ td >
< td >
年龄要求
</ td >
< td >
学历要求
</ td >
< td >
工作地点
</ td >
< td >
发布时间
</ td >
< td >
删除
</ td >
</ tr >
<
do   while   not  rs.eof 
strzpzw
= rs( " zpzw " )
if   len (strzpzw) > 5   then
strzpzw
= left (strzpzw, 5 ) & " "
end   if
%
>
< tr >
< td  >
< a href = " # "  onClick = " window.open('Editzhaopin.asp?did=<%=rs( " did " )%>','','width=640,height=580,scrollbars=yes') " >
< % = strzpzw% >
</ a >
</ td >

< td >
< % = rs( " xbyq " )% >
</ td >
< td >
< % = rs( " nlyq " )% >
</ td >
< td >
< % = rs( " xlyq " )% >
</ td >
< td >
< % = rs( " gzdd " )% >
</ td >
< td >
< % = datevalue (rs( " fbsj " ))% >
</ td >
< td >
< a href = " ?Action=Del&did=<%=rs( " did " )%>&cid=<%=cid%> "  OnClick = " return ConfirmDel(); " > 删除 </ a >
</ td >
</ tr >
< %
rs.movenext
loop
rs.close

%
>
</ table >
5.数据库链接对象(将如下代码拷至conn.asp页面中,单独的作为链接对象)
其他页面要用的时候用<!--#include file="conn.asp"-->放至页面顶部就可以调用了
 1  < %
 2  dim  conn,connstr,db
 3  db = " databases/syb.mdb "
 4  Set  conn  =  Server.CreateObject( " ADODB.Connection " )
 5  connstr = " Provider=Microsoft.Jet.OLEDB.4.0;Data Source= "   &  Server.MapPath( "" & db & "" )
 6  conn.Open connstr
 7  sub  closedb()
 8      conn.close
 9       set  conn = nothing
10  end sub
11  % >
6、修改数据
 1  < ! -- #include file = " conn.asp " -->
 2  < %
 3  did = request.querystring( " did " )
 4  strsql = " select * from dwzp where did= " & did
 5  set  rs = server.CreateObject( " Adodb.Recordset " )
 6  rs.open strsql,conn, 2 , 2
 7  if  request.QueryString( " action " ) = " Modify "   then
 8  txtzpzw = request( " txtzpzw " )
 9  txtzpzy = request( " txtzpzy " )
10  txtzyyq = request( " txtzyyq " )
11  txtsex = request( " txtsex " )
12  txtage = request( " txtagestart " ) & " - " & request( " txtageend " )
13  txtxlyq = request( " txtxlyq " )
14  txthkdz = request( " txthkdz " )
15  txtgzdz = request( " txtgzdz " )
16  txtgznx = request( " txtgznx " )
17  txtyx = request( " txtyx " )
18  txtgzfs = request( " txtgzfs " )
19  txtqtyq = request( " txtqtyq " )
20  rs( " zpzw " ) = txtzpzw
21  rs( " zpzy " ) = txtzpzy
22  rs( " zyyq " ) = txtzyyq
23  rs( " xbyq " ) = txtsex
24  rs( " nlyq " ) = txtage
25  rs( " xlyq " ) = txtxlyq
26  rs( " hkszd " ) = txthkdz
27  rs( " gzdd " ) = txtgzdz
28  rs( " gznx " ) = txtgznx
29  rs( " yx " ) = txtyx
30  rs( " gzfs " ) = txtgzfs
31  rs( " qtyq " ) = txtqtyq
32  rs.update
33  rs.close
34  Response.write  " <Script>alert('企业职位招骋修改成功!');opener.location.reload();window.close();</Script> "
35  response.end
36  end   if
37  % >
38 
39  如果不是修改的话将取的数据填充table中
40  < tr >
41         < td >& nbsp; </ td >
42         < td >* 职业要求 </ td >
43         < td colspan = " 3 " >< textarea name = " txtzyyq "  cols = " 50 "  rows = " 5 "  id = " txtzyyq " >< % = rs( " zyyq " )% ></ textarea ></ td >
44       </ tr >
45       < tr >
46         < td >& nbsp; </ td >
47         < td >* 性别要求 </ td >
48         < td width = " 182 " >< select  name = " txtsex "  size = " 1 "  id = " txtsex " >
49         < option  value = " <%=rs( " xbyq " )%> "  selected = " selected " >< % = rs( " xbyq " )% ></ option >
50           < option  value = " 不限 "   > 不限 </ option >
51           < option  value = " " > </ option >
52           < option  value = " " > </ option >
53         </ select >        </ td >
54         < td width = " 82 " >* 年龄要求 </ td >
55         < td width = " 216 " >< input name = " txtagestart "  type = " text "  id = " txtagestart "  size = " 3 "  maxlength = " 2 "  value = " <%=left(rs( " nlyq " ),2)%> " />
56          至
57           < input name = " txtageend "  type = " text "  id = " txtageend "  size = " 3 "  maxlength = " 2 "  value = " <%=right(rs( " nlyq " ),2)%> "   /></ td >
58       </ tr >
59       < tr >
60         < td >& nbsp; </ td >
61         < td >* 学历要求 </ td >
62         < td >< select  name = " txtxlyq "  size = " 1 "  id = " txtxlyq " >
63           < option  value = " 不限 " > 不限 </ option >
64           < option  value = " <%=rs( " xlyq " )%> "  selected = " selected " >< % = rs( " xlyq " )% ></ option >
65           < option  value = " 高中、技校 " > 高中、技校 </ option >
66           < option  value = " 中专 " > 中专 </ option >
67           < option  value = " 大专 " > 大专 </ option >
68           < option  value = " 本科 " > 本科 </ option >
69           < option  value = " 硕士 " > 硕士 </ option >
70           < option  value = " 博士 " > 博士 </ option >
71        
72         </ select >        </ td >
73 
74 
7、添加数据
 1 < ! -- #include file = " conn.asp " -->
 2 < ! -- #include file = " sybadmin/md5.asp " -->
 3 < %
 4 cid = request.QueryString( " cid " )
 5 txtzpzw = request( " txtzpzw " )
 6 txtzpzy = request( " txtzpzy " )
 7 txtzyyq = request( " txtzyyq " )
 8 txtsex = request( " txtsex " )
 9 txtage = request( " txtagestart " ) & " - " & request( " txtageend " )
10 txtxlyq = request( " txtxlyq " )
11 txthkdz = request( " txthkdz " )
12 txtgzdz = request( " txtgzdz " )
13 txtgznx = request( " txtgznx " )
14 txtyx = request( " txtyx " )
15 txtgzfs = request( " txtgzfs " )
16 txtqtyq = request( " txtqtyq " )
17 set  rs = server.CreateObject( " adodb.recordset " )
18 sqlstr = " select * from dwzp "
19 rs.open sqlstr,conn, 1 , 3
20 rs.addnew
21 rs( " cid " ) = cid
22 rs( " zpzw " ) = txtzpzw
23 rs( " zpzy " ) = txtzpzy
24 rs( " zyyq " ) = txtzyyq
25 rs( " xbyq " ) = txtsex
26 rs( " nlyq " ) = txtage
27 rs( " xlyq " ) = txtxlyq
28 rs( " hkszd " ) = txthkdz
29 rs( " gzdd " ) = txtgzdz
30 rs( " gznx " ) = txtgznx
31 rs( " yx " ) = txtyx
32 rs( " gzfs " ) = txtgzfs
33 rs( " qtyq " ) = txtqtyq
34 rs( " fbsj " ) = now ()
35 rs.update
36 response.Write " <script>alert('招骋职位发布成功!');window.location.href('qymain.asp?cid= " & rs( " cid " ) & " ')</script> "
37 % >
8、取参数的值
1 session( " username " )
2 request.querystring( " id " )
3 request( " id " )
4 request.form( " 文本框名 " )
5
9、弹出窗口操作完后,如何更新主页面
1  Response.write  " <Script>alert('企业职位招骋修改成功!');opener.location.reload();window.close();</Script> "
2  response.end

10、向弹出窗口传递值
1 < a href = " # "  onClick = " window.open('Editzhaopin.asp?did=<%=rs( " did " )%>','','width=640,height=580,scrollbars=yes') " >
2 < % = strzpzw% >
3 </ a >

你可能感兴趣的:(VBScript)