ASP连ACCESS的连接,添加,删除,修改的代码
展开全部
全部显示、删除和编辑可以用一个页面实现(类似于后台管理),代码如下:
<%
'======数据库连接代码省略===
Dim Rs,SQL
Set Rs=Server.CreateObject("adodb.recordset")
Sql="Select ID,zbgb from [gb]"
Rs.open sql,conn,1,1
if Rs.eof or Rs.bof then
Response.write"没有纪录"
else
Do while not(Rs.eof or rs.bof)
Response.write Rs(1)&" <a href='del.asp?ID="&Rs(0)&"' target='_blank'>删除</a> <a href='modify.asp?ID="&Rs(0)&"' target='_blank'>修改</a><br>"
Rs.movenext
Loop
end if
Set Rs=nothing
%>
删除处理页面del.asp:
<%
'======数据库连接代码省略===
Dim Rs,SQL,ID
ID=Trim(Request("ID"))
if Not(IsNumeric(ID)) then
Response.write "非法参数"
else
Set Rs=Server.CreateObject("adodb.recordset")
Sql="Select * from [gb] where ID="&ID&""
Rs.open sql,conn,1,1
if Rs.eof or Rs.bof then
Response.write"参数错误,指定内容不存在"
else
Conn.execute("delete * from [Gb] where ID="&ID&"")
Response.write"删除成功"
end if
Set Rs=nothing
end if
%>
编辑处理页面modify.asp:
<%
'======数据库连神唯接代码省略===
Dim Rs,SQL,ID,action
action=Trim(Request("action"))
if action="Modify" then
call Modify()
else
call ShowIT()
end if
Sub ShowIT()
ID=Trim(Request("ID"))
if Not(IsNumeric(ID)) then
Response.write "非法参数"
else
Set Rs=Server.CreateObject("adodb.recordset")
Sql="Select * from [gb] where ID="&ID&"游肆培"
Rs.open sql,conn,1,1
if Rs.eof or Rs.bof then
Response.write"参数错误,指定内容不存在"
else
Response.write"<form action='modify.asp?action=Modify' method='post'>"
Response.write"<input type='text' name='zbgb' value='"&Rs("zbgb")&"'>"
Response.write"<input type='submit' value='修改'>"
Response.write"<input type='hidden' value='"&Rs("ID")&"'>"
Response.write"</form>"
end if
Set Rs=nothing
end if
end Sub
Sub Modify()
Dim zbgb,RID
zbgb=Trim(Request.form("zbgb"))
RID=Trim(Request.form("ID"))
Conn.execute("Update [Gb] set zbgb='"zbgb&&"' where ID="&RID&")
end Sub
%>
添加页面代码省雹嫌略
添加处理页面核心代码:
<%
Set Rs=Server.CreateObject("adodb.recordset")
Sql="insert into [gb](zbgb) values('"&Request.form("zbgb")&"')"
Rs.open Sql,conn,1,3
set rs=nothing
%>
<%
'======数据库连接代码省略===
Dim Rs,SQL
Set Rs=Server.CreateObject("adodb.recordset")
Sql="Select ID,zbgb from [gb]"
Rs.open sql,conn,1,1
if Rs.eof or Rs.bof then
Response.write"没有纪录"
else
Do while not(Rs.eof or rs.bof)
Response.write Rs(1)&" <a href='del.asp?ID="&Rs(0)&"' target='_blank'>删除</a> <a href='modify.asp?ID="&Rs(0)&"' target='_blank'>修改</a><br>"
Rs.movenext
Loop
end if
Set Rs=nothing
%>
删除处理页面del.asp:
<%
'======数据库连接代码省略===
Dim Rs,SQL,ID
ID=Trim(Request("ID"))
if Not(IsNumeric(ID)) then
Response.write "非法参数"
else
Set Rs=Server.CreateObject("adodb.recordset")
Sql="Select * from [gb] where ID="&ID&""
Rs.open sql,conn,1,1
if Rs.eof or Rs.bof then
Response.write"参数错误,指定内容不存在"
else
Conn.execute("delete * from [Gb] where ID="&ID&"")
Response.write"删除成功"
end if
Set Rs=nothing
end if
%>
编辑处理页面modify.asp:
<%
'======数据库连神唯接代码省略===
Dim Rs,SQL,ID,action
action=Trim(Request("action"))
if action="Modify" then
call Modify()
else
call ShowIT()
end if
Sub ShowIT()
ID=Trim(Request("ID"))
if Not(IsNumeric(ID)) then
Response.write "非法参数"
else
Set Rs=Server.CreateObject("adodb.recordset")
Sql="Select * from [gb] where ID="&ID&"游肆培"
Rs.open sql,conn,1,1
if Rs.eof or Rs.bof then
Response.write"参数错误,指定内容不存在"
else
Response.write"<form action='modify.asp?action=Modify' method='post'>"
Response.write"<input type='text' name='zbgb' value='"&Rs("zbgb")&"'>"
Response.write"<input type='submit' value='修改'>"
Response.write"<input type='hidden' value='"&Rs("ID")&"'>"
Response.write"</form>"
end if
Set Rs=nothing
end if
end Sub
Sub Modify()
Dim zbgb,RID
zbgb=Trim(Request.form("zbgb"))
RID=Trim(Request.form("ID"))
Conn.execute("Update [Gb] set zbgb='"zbgb&&"' where ID="&RID&")
end Sub
%>
添加页面代码省雹嫌略
添加处理页面核心代码:
<%
Set Rs=Server.CreateObject("adodb.recordset")
Sql="insert into [gb](zbgb) values('"&Request.form("zbgb")&"')"
Rs.open Sql,conn,1,3
set rs=nothing
%>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询