威凡网全力打造:网页编程、软件开发编程、平面设计、服务器端开发、操作系统等在线学习平台!学编程,上威凡网!
ASP教程>> ASP基础 应用技巧 数据库相关 ASP类 存储过程 FSO专栏 ASP其他
当前位置:首页 > ASP教程 > 应用技巧
上一节 下一节
 asp 删除数据并同时删除图片的代码
第一种方法:这个是删除单字段图片的代码。比较简单,因为图片字段已经预先存在数据库表的bookpic的字段里面了。
复制代码 代码如下:

<!--#include file="conn.asp"-->
<%
fileid=trim(request("fileid"))'要删除的记录id
set rs=server.createobject("adodb.recordset")
sql="select * from shop_books where bookid=3090"
rs.open sql,conn,3,2
upfile=rs("bookpic") '带路径和文件名
set fso=server.createobject("scripting.filesystemobject")
fso.deletefile(server.mappath(upfile))
set fso=nothing
rs.delete
rs.update
rs.close
set rs=nothing
%>

第二种方法:对于多图片的
asp程序下大家在添加信息的时候可以用ewebeditor,这个可以将文章种的图片提取后放到一个字段里面。
复制代码 代码如下:

id=request("id")
if id="" then
response.write("<script>alert('删除操作失败:请选择需要删除的信息!');hitory.go(-1);</script>")
else
id=split(id,",")
for i=0 to ubound(id)
set ors=server.createobject("adodb.recordset")
ssql = "select d_savepathfilename from "&data&" where id="&id(i)&""
ors.open ssql, conn, 0, 1
if not ors.eof then
assavepathfilename = ors("d_savepathfilename")
else
assavepathfilename=""
end if
ors.close
set ors=nothing
dim asavepathfilename
if len(asavepathfilename)>0 then
asavepathfilename = split(assavepathfilename, "|")
dim n
for n = 0 to ubound(asavepathfilename)
' 按路径文件名删除文件
call dodelfile(asavepathfilename(n))
next
'删除文章 www.jb51.net
conn.execute("delete from article where id="&id(i)&"")
next
end if
sub dodelfile(spathfile)
'on error resume next
dim ofso
set ofso = server.createobject("scripting.filesystemobject")
if objfso.fileexists(server.mappath(spathfile)) then
ofso.deletefile(server.mappath(spathfile))
end if
set ofso = nothing
end sub

申明:本教程内容由威凡网编辑整理并提供IT程序员分享学习,如文中有侵权行为,请与站长联系(QQ:254677821)!
上一节 下一节
相关教程  
其他教程  
ASP基础
应用技巧
数据库相关
ASP类
存储过程
FSO专栏
ASP其他

违法和不良信息举报中心】邮箱:254677821@qq.com
Copyright©威凡网 版权所有 苏ICP备2023020142号
站长QQ:254677821