ASP+ACCESS 温故而知新

set conn = server.CreateObject("ADODB.connection")
conn.open "provider=microsoft.jet.oledb.4.0;data source="&Server.MapPath("../include/#test.mdb")    

dim action
action = request.QueryString("action")
 

'添加数据
if action = "add" then
    sql = "select * from Datas"
    set rs = server.CreateObject("ADODB.recordset")
    rs.open sql,conn,3,3
    rs.addnew
         rs("xxx") = request.Form("xxx")
         … …       

         rs.update
         response.write("<script type='text/javascript'>alert('添加成功!'); location.href=xxx.asp'</script>")        

         rs.close
         set rs = nothing       
 

'修改数据
elseif action = "edit" then
    dim getID
    getID = request.QueryString("id")
    sql = "select * from Datas where id="&getID
    set rs = server.CreateObject("ADODB.recordset")
    rs.open sql,conn,3,3 
         rs("Name") = request.Form("Name")
         … …       
         rs.update
         response.write("修改成功!")                  

         rs.close
         set rs = nothing
        

'删除数据
elseif action = "del" then
    getID = request.QueryString("id")
    sql = "delete from Datas where id="&getID
    conn.execute(sql)
    response.write("<script type='text/javascript'>alert('已删除!'); location.href='admin.asp'</script>")   
end if

conn.close
set conn = nothing

 

QA1、数据可以读取,但是到了修改、添加、删除时都报错

  1. Mdb文件是否只读
  2. 存放mdb文件的磁盘格式是否为NTFS
posted @ 2012-08-16 10:19  远方V3  阅读(177)  评论(0编辑  收藏  举报