世界因你而精彩  
日历
<2012年7月>
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234
统计
  • 随笔 - 169
  • 文章 - 1
  • 评论 - 138
  • 引用 - 0

导航

常用链接

留言簿(9)

随笔分类(163)

随笔档案(154)

文章档案(1)

新闻档案(1)

相册

收藏夹(1)

个人杂杂

友情链接

自学考试

资料搜索

最新随笔

搜索

  •  

积分与排名

  • 积分 - 358366
  • 排名 - 153

最新评论

阅读排行榜

评论排行榜

 
这两天小弟提了个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>&nbsp;</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>&nbsp;</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>&nbsp;<%=rs(0)%></td>
    <td>&nbsp;<%=rs(1)%></td>
    <td>&nbsp;<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>

posted on 2007-12-13 14:24 张秀兰 阅读(530) 评论(1)  编辑  收藏 所属分类: 资料查找
评论:
  • # re: asp access数据库预处理方法  ghost210 Posted @ 2012-07-06 11:49
    谢谢了,我从网上找了很多资料,发现从您这里解决了。
    太感谢了  回复  更多评论   


只有注册用户登录后才能发表评论。


网站导航:
 
 
Copyright © 张秀兰 Powered by: 博客园 模板提供:沪江博客