📄 editresu.asp
字号:
<%@ LANGUAGE="VBScript" %>
<!--#include file="globvars.asp"-->
<!--#include file="commfunc.asp"-->
<%response.buffer = true%>
<%
if session("DataAdmi_Access")=0 then
response.redirect RediPage
end if
%>
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 2.0">
<title>数据修改删除增加</title>
<%
Function fiel_valu(ByVal f, ByVal s)
' Input: f = field object
' s = string from form field
' Output:
Dim x
x = " "
if f.Type = adSmallInt then
x = CInt(s)
elseif f.Type = adInteger then
x = CLng(s)
elseif f.Type = adSingle then
x = CSng(s)
elseif f.Type = adDouble then
x = CDbl(s)
elseif f.Type = adCurrency then
x = CCur(s)
elseif f.Type = adBoolean then
x = CBool(s)
elseif f.Type = adUnsignedTinyInt then
x = CByte(s)
elseif f.Type = adChar then
x = "'" & inse_apos(s) & "'"
elseif f.Type = adDBDate then
x = "#" & s & "#"
elseif f.Type = adDBTime then
x = "#" & s & "#"
elseif f.Type = adDBTimeStamp then
x = "#" & s & "#"
elseif f.Type = adVarChar then
x = "'" & inse_apos(s) & "'"
elseif f.Type = adLongVarChar then
x = "'" & inse_apos(s) & "'"
else
x = "'" & inse_apos(s) & "'"
end if
fiel_valu = x
End Function
Dim FielName, FielValu, PageNumb, RetuPage, Conn, Rec, Rec2, n, Str, Sql
FielName = Request.QueryString("fn")
FielValu = CInt(Request.QueryString("fv"))
PageNumb = CInt(Request.QueryString("pg"))
RetuPage = "datalist.asp?pg=" & PageNumb
call open_data(Conn, session("DataAdmi_DataName"))
if request.form("submit") = "Delete" then
Sql = "SELECT * FROM " & session("DataAdmi_TablName") & " WHERE "
Sql = Sql & FielName & "=" & FielValu
Set Rec = Conn.Execute(Sql)
if Rec.EOF then
BodyText = "ERROR. There is no record with the <strong>" & _
FielName & "=" & FielValu & "</strong>. No record was deleted."
else
Sql = "SELECT * FROM " & session("DataAdmi_TablName")
Set Rec2 = Conn.Execute(Sql)
Rec2.MoveNext
if Rec2.EOF then
BodyText = "ERROR. You cannot delete the last record of a database!"
else
Sql = "DELETE * FROM " & session("DataAdmi_TablName") & " WHERE "
Sql = Sql & FielName & "=" & FielValu
Conn.Execute(Sql)
BodyText = "The record <strong>" & FielName & "=" & FielValu & _
"</strong> was deleted."
end if
end if
Rec.Close
set Rec = Nothing
elseif request.form("submit") = "Update" then
Sql = "SELECT * FROM " & session("DataAdmi_TablName") & " WHERE "
Sql = Sql & FielName & "=" & FielValu
Set Rec = Conn.Execute(Sql)
if Rec.EOF then
BodyText = "ERROR. There is no record with the <strong>" & _
FielName & "=" & FielValu & "</strong>. No record was updated."
else
Sql = "UPDATE " & session("DataAdmi_TablName") & " SET "
n = 0
for each fld in Rec.Fields
if fld.Attributes <> adAutoIncrement AND request.form(fld.Name) <> "" then
if n <> 0 then
Sql = Sql & ","
end if
Sql = Sql & fld.Name & "=" & fiel_valu(fld, request.form(fld.Name))
n = 1
end if
next
Sql = Sql & " WHERE " & FielName & "=" & FielValu
Conn.execute(Sql)
BodyText = "The record <strong>" & FielName & "=" & FielValu & _
"</strong> was updated."
end if
Rec.Close
set Rec = Nothing
elseif request.form("submit") = "Add" then
Sql = "SELECT * FROM " & session("DataAdmi_TablName")
Set Rec = Conn.Execute(Sql)
Sql = "INSERT into " & session("DataAdmi_TablName") & " ("
Str = "("
n = 0
for each fld2 in Rec.Fields
if fld2.Attributes <> adAutoIncrement AND request.form(fld2.Name) <> "" then
if n <> 0 then
Sql = Sql & ","
Str = Str & ","
end if
Sql = Sql & fld2.Name
Str = Str & fiel_valu(fld2, request.form(fld2.Name))
n = 1
end if
next
Sql = Sql & ") values " & Str & ")"
Conn.execute(Sql)
BodyText = "The record was added."
Rec.Close
set Rec = Nothing
end if
Conn.close
set Conn = nothing
%>
</head>
<body bgcolor="#FFFFFF">
<table border="0" cellpadding="8" cellspacing="0" width="100%">
<tr>
<td valign="top" width="15%" bgcolor="#C0C0C0"><a
href="<% response.write RetuPage %>"><font size="2"><strong>返回列表</strong></font></a>
<p><a
href="<%=HomePage%>"><font size="2"><strong>Home</strong></font></a></p>
</td>
<td valign="top" width="85%">
<p align="center"><font
color="#FF0000" size="3" ><strong>数据更新</strong></font></p>
<p><% Response.Write BodyText %> </p>
</td>
</tr>
</table>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -