这两天小弟提了个Bug,也是在网上找了些资料,才搞定了它,顺便在此作个笔记
重点作解析对象:
Sub SaveAdd()
cm.CommandText = "INSERT INTO [xm_news] (n_title,n_pic,n_Info,n_Atime) VALUES(?,?,?,?)"
cm.Prepared = True
cm.Parameters.Append cm.CreateParameter("n_title",200, ,255)
cm.Parameters.Append cm.CreateParameter("n_pic",200, ,255)
cm.Parameters.Append cm.CreateParameter("n_Info",200, ,-1)
cm.Parameters.Append cm.CreateParameter("n_Atime",200, ,255)
cm("n_title")=Request.Form("title")
cm("n_pic")=Request.Form("defaultpic")
cm("n_Info")=Request.Form("info")
cm("n_Atime")=now
cm.Execute
Response.Write ("<script>alert('添加成功!');location='?'</script>")
End Sub
cm.Parameters.Append cm.CreateParameter("n_Info",200, ,-1)
'得是-1
<!--#include file="inc.asp"-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>后台产品管理</title>
<STYLE type=text/css>BODY {
BACKGROUND-COLOR: #ffffff
}
.toptable1 {
COLOR: #000000; BACKGROUND-COLOR: #d2d6dc
}
.toptable2 {
BACKGROUND-IMAGE: url(images/topdi.gif); COLOR: #000000
}
.banner {
BACKGROUND-IMAGE: url(images/topdi.gif); COLOR: #7089a9; HEIGHT: 25px
}
.tablecolor {
WIDTH: 98%; WORD-BREAK: break-all; BACKGROUND-COLOR: #888888
}
.tablebody {
BACKGROUND-COLOR: #ffffff
}
TD {
FONT-SIZE: 12px; COLOR: #000000
}
INPUT {
BORDER-RIGHT: #333333 1px solid; BORDER-TOP: #333333 1px solid; FONT-SIZE: 9pt; BACKGROUND: url(images/input.gif) #ffffff; BORDER-LEFT: #333333 1px solid; COLOR: #000000; BORDER-BOTTOM: #333333 1px solid; FONT-FAMILY: verdana
}
A:link {
COLOR: #666666; TEXT-DECORATION: none
}
A:active {
COLOR: #666666; TEXT-DECORATION: none
}
A:visited {
COLOR: #666666; TEXT-DECORATION: none
}
A:hover {
COLOR: #339900; TEXT-DECORATION: underline
}
A.a:link {
COLOR: #ea7500; TEXT-DECORATION: none
}
A.a:visited {
COLOR: #ea7500; TEXT-DECORATION: none
}
A.a:active {
COLOR: #ea7500; TEXT-DECORATION: none
}
A.a:hover {
COLOR: #ea7500; TEXT-DECORATION: underline
}
</STYLE>
</head>
<body>
<%
Call Checkadmin()
ID=CheckNumeric(Request("ID"))
Action = Trim(Request.QueryString("Action"))
DatabasePath="../database/database.mdb"
Set Conn = Server.Createobject("Adodb.Connection")
Conn.Open "Provider=Microsoft.Jet.Oledb.4.0;Data Source="&Server.Mappath(DatabasePath)
'Call OpenDatabase()
Set cm= Server.CreateObject("ADODB.Command")
Set cm.ActiveConnection = Conn
Select Case Action
Case "Edit"
Call Edit()
Case "SaveAdd"
Call SaveADD()
Case "Add"
Call Add()
Case "SaveEdit"
Call Saveedit()
Case "Del"
Call Del()
Case Else
call Normal()
End Select
call CloseDatabase()
Sub Edit()
Set Rs = Conn.Execute("SELECT * From xm_news Where n_Id ="&id&"")
%><form action="?Action=SaveEdit&ID=<%=RS("n_ID")%>" method="post" name="form1" >
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#95DDFF">
<tr bgcolor="#ECF4FB">
<td width="14%" height="30">新闻标题:</td>
<td>
<input name="title" type="text" id="title" value="<%=RS("n_title")%>" size="50"></td>
</tr>
<tr bgcolor="#ECF4FB">
<td height="30">新闻图片:</td>
<td>
<INPUT name="DefaultPic" type="text" id="DefaultPic" value="<%=rs("n_pic")%>">
<br> <IFRAME ID="DefaultPic1" SRC="upload.asp?t=1" FRAMEBORDER="0" SCROLLING="no" WIDTH="500" HEIGHT="30"></IFRAME></td>
</tr>
<tr>
<tr bgcolor="#ECF4FB">
<td height="30">新闻描述:</td>
<td>
<textarea name="info" cols="50" id="textarea"><%=rs("n_info")%></textarea>
</tr>
<tr bgcolor="#ECF4FB">
<td> </td>
<td>
<input type="submit" name="bottom2" value="提交" > <input type="reset" name="Submit2" value="重置"></td>
</tr>
</table></form>
<%
End Sub
Sub SAVEEdit()
cm.CommandText = "Update xm_news Set n_title= ?,n_pic= ?, n_info=? Where n_Id="&id&""
cm.Prepared = True
cm.Parameters.Append cm.CreateParameter("n_title",200, ,255)
cm.Parameters.Append cm.CreateParameter("n_pic",200, ,255)
cm.Parameters.Append cm.CreateParameter("n_Info",200, ,-1)
cm("n_title")=Request.Form("title")
cm("n_pic")=Request.Form("Defaultpic")
cm("n_Info")=Request.Form("info")
cm.Execute
'Conn.Execute("Update xm_news Set n_title='"&Request.Form("title")&"',n_pic='"&Request.Form("Defaultpic")&"',n_info='"&Request.Form("info")&"' Where n_Id="&id&"")
Response.Write ("<script>alert('修改成功!');location='?'</script>")
End Sub
Sub SaveAdd()
cm.CommandText = "INSERT INTO [xm_news] (n_title,n_pic,n_Info,n_Atime) VALUES(?,?,?,?)"
cm.Prepared = True
cm.Parameters.Append cm.CreateParameter("n_title",200, ,255)
cm.Parameters.Append cm.CreateParameter("n_pic",200, ,255)
cm.Parameters.Append cm.CreateParameter("n_Info",200, ,-1)
cm.Parameters.Append cm.CreateParameter("n_Atime",200, ,255)
cm("n_title")=Request.Form("title")
cm("n_pic")=Request.Form("defaultpic")
cm("n_Info")=Request.Form("info")
cm("n_Atime")=now
cm.Execute
Response.Write ("<script>alert('添加成功!');location='?'</script>")
End Sub
Sub Del()
Conn.Execute("Delete from xm_news where n_Id ="&ID&"")
Response.Write ("<script>alert('删除成功!');location='?'</script>")
End Sub
Sub Add()
%>
<form action="?Action=SaveAdd" method="post" name="form1" >
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#95DDFF">
<tr bgcolor="#ECF4FB">
<td width="14%" height="30">新闻标题:</td>
<td>
<input name="title" type="text" id="title" size="50" ></td>
</tr>
<tr bgcolor="#ECF4FB">
<td height="30">新闻图片test:</td>
<td>
<INPUT name="DefaultPic" type="text" id="DefaultPic"> <br> <IFRAME ID="DefaultPic1" SRC="upload.asp?t=1" FRAMEBORDER="0" SCROLLING="no" WIDTH="500" HEIGHT="30"></IFRAME></td>
</tr>
<tr>
<tr bgcolor="#ECF4FB">
<td height="30">新闻描述:</td>
<td>
<textarea name="info" cols="50" id="info"></textarea>
</tr>
<tr bgcolor="#ECF4FB">
<td> </td>
<td>
<input type="submit" name="bottom" value="提交" > <input type="reset" name="Submit" value="重置"></td>
</tr>
</table>
</form>
<%
End Sub
sub normal%>
<table width="100%" border="0" cellpadding="2" cellspacing="1" bgcolor="#95DDFF">
<tr bgcolor="#ECF4FB">
<td width="187" bgcolor="#ECF4FB"><strong>ID</strong></td>
<td width="294" bgcolor="#ECF4FB"><strong>标题</strong></td>
<td width="279" bgcolor="#ECF4FB"><strong>编辑</strong></td>
</tr>
<%
PageNo=CheckNumeric(Request("pageno"))
Sql="select n_id,n_title from xm_news order by n_id desc"
set rs=server.CreateObject("adodb.recordset")
rs.open sql,conn,1,1
Pasz=12
Total=INT(rs.RecordCount\Pasz+1)
rs.PageSize=Cint(Pasz)
if pageno<1 or PageNo="" then
pageno=1
end if
if pageno > Total then
pageno=Total
end if
rs.AbsolutePage=pageno
position=rs.PageSize*pageno
pagebegin=position-rs.PageSize+1
if position<rs.RecordCount then
pagend=position
else
pagend=rs.RecordCount
end if
rs.AbsolutePosition=pagebegin
for i =pagebegin to pagend
%>
<tr bgcolor="#ECF4FB">
<td> <%=rs(0)%></td>
<td> <%=rs(1)%></td>
<td> <a href="?Action=Edit&ID=<%=RS(0)%>">编辑</a>|<a href="?Action=Del&ID=<%=RS(0)%>">删除</a></td>
</tr>
<%
rs.movenext
next
rs.close
set rs=nothing
%>
</table>
<table align=center>
<tr>
<td align=right style="border:0px"><a href="?pageno=<%=pageno-1%>"><br>[上一页]</a></td>
<td align=left style="border:0px"><a href="?pageno=<%=pageno+1%>"><br>[下一页]</a></td>
</tr>
</table>
<%end sub%>
</body>
</html>