当前位置:编程学习 > asp >>

(ADODB.Command)对象的用法,用CASE调用的REM/DEL/UPDATE/

答案:<!--#include file="conn.asp"-->
<%set rs=server.createobject("adodb.recordset")
sql="select * from jtopic order by j_id desc"
rs.open sql,conn,1,1
%>
<script language="javascript">
function check1(i,o)
{
document.form.text2.value=i;
document.form.word2.value=o;
}
</script>

<form name="form" method="post" action="sort_in.asp">
<br><b>&nbsp;专题类别:</b>
<input type="hidden" name="options" value=''>
&nbsp;<select name="jtop" id="jtop" onchange="check1(document.form.jtop.options[document.form.jtop.selectedIndex].lable,document.form.jtop.options[document.form.jtop.selectedIndex].title)">
<% do while not rs.eof %>
<option value="<%=rs("j_id")%>" lable="<%=rs("j_name")%>" title="<% =rs("j_flag") %>"><%=rs("j_name")%></option>
<%
rs.movenext
loop
%></select>
<input type="submit" name="Submit" value="删 除" onclick="form.options.value='del'"><p>
&nbsp;<input type="text" name="word1" size=57 value="" maxlength="50" style="width: 369; height: 22">&nbsp;
<input name="tui1" type="radio" id="tui" value="0" checked>默认<font color=red><b>0</b></font>
<input name="tui1" type="radio" id="tui" value="1">推荐<font color=red><b>1</b></font>
<input type="submit" name="Submit1" value="添 加" onclick="form.options.value='new'">&nbsp;</p><p>
&nbsp;<input type="text" name="text2" size=57 value="" maxlength="50" style="width: 370; height: 22">
<input type="text" name="word2" size=57 value="" maxlength="50" style="width: 70; height: 23">&nbsp;
<input type="submit" name="Submit2" value="修 改" onclick="form.options.value='rename'">&nbsp; </p>
</form> 

+++++++++++ sort_in.asp +++++++++++++++++++++++++++++++++++
<!--#include file="conn.asp"-->
<%
dim cmdTemp

select case request.form("options")
case "rename"
on error resume next
Set cmdTemp = Server.CreateObject("ADODB.Command")
set rs=server.createobject("adodb.recordset")
cmdTemp.CommandText = "SELECT * FROM jtopic where j_id=" & request.form("jtop")
cmdTemp.CommandType = 1
Set cmdTemp.ActiveConnection = conn
rs.Open cmdTemp, , 1, 3
if err.Number<>0 then
err.clear
response.write " <br>数 据 库 操 作 失 败 ! "
else
rs("j_name") = request.form("text2")
rs("j_flag") = request.form("word2")
rs.Update
rs.Close
set rs=nothing
set cmdTemp=nothing
finished
end if
case "del"
Rem 删除栏目 /. 注释或标记语句:Rem 格式:Rem [注释或标记](解释:可以当作标记供跳转语句使用,也可以当作脚本的注释使用)
on error resume next
sql="delete from jtopic where j_id=" & request.form("jtop")
conn.execute sql
if err.Number<>0 then
err.clear
response.write " <br>数 据 库 操 作 失 败 ! "
else
finished
end if
case "new"
on error resume next
Set cmdTemp = Server.CreateObject("ADODB.Command")
set rs=server.createobject("adodb.recordset")
cmdTemp.CommandText = "SELECT * FROM jtopic where (j_id IS NULL)"
cmdTemp.CommandType = 1
Set cmdTemp.ActiveConnection = conn
rs.Open cmdTemp, , 1, 3
if err.Number<>0 then
err.clear
response.write " <br>数 据 库 操 作 失 败 ! "
else
rs.AddNew
rs("j_name") = request.form("word1")
rs("j_flag") = request.form("tui1")
rs.Update
rs.Close
set rs=nothing
set cmdTemp=nothing
finished
end if
end select

sub finished()
%>
<html>
<head><title>修改成功</title>
<meta http-equiv="refresh" content='0; URL=sort.asp'>
<link rel="stylesheet" href=>
<body>
<br><br><p align="center"><b>类别修改成功!</b></p><% end sub %>

上一个:C#多线程编程实例实战
下一个:ASP中正则表达式的应用

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,