前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >asp连接access,增删改查

asp连接access,增删改查

作者头像
lpe234
发布2020-07-27 17:10:56
3.7K0
发布2020-07-27 17:10:56
举报
文章被收录于专栏:若是烟花若是烟花若是烟花

环境: ie11、win8.1 x64

推荐教程:http://www.w3school.com.cn/asp/index.asp http://www.w3school.com.cn/ado/index.asp


其他的,如何开启IIS,access使用。都是些基础或者了解下的东西。用到自己搜吧。


1、首先呢,使用脚本VBScript。Firefox不支持,只能使用IE了。

由于需要调试,查看服务器出错等信息。需要设置下IE。

“设置”-》“Internet选项”-》“高级”-》取消“显示友好http错误消息”

这样就有可能看到,服务器错误信息。还需要设置下服务器。

2、IIS设置显示,错误信息

点选相应网站,找到“asp”图标。在“编译”-》“调试属性”-》“将错误发送到浏览器”属性改为“True”

这样浏览器就不会只是显示,“http 500 服务器内部错误”。而是显示具体的错误信息。

3、错误信息

ADODB.Connection 错误 '800a0e7a' 
未找到提供程序。该程序可能未正确安装。 
/index.asp,行 4

查找得知,是 win7,8 x64的原因。

在服务器。“应用程序池”-》“设置应用程序池默认设置”-》“常规”-》“启用32位程序”属性 改为 “True”。即可正常连接access数据库了。

4、asp,access 乱码问题解决

http://www.web258.cn/fileshow.asp?id=1176


1、数据库连接代码

<%
    set conn = Server.CreateObject("ADODB.Connection")
    conn.Provider = "Microsoft.Jet.OLEDB.4.0"
    conn.Open "D:\data.mdb"
    '数据库的连接可以使用 直连access,为了数据安全,一般使用odbc连接。
%>

简单的demo

1、index.asp

<!-- 解决乱码问题 -->
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%Session.CodePage = 65001%>

<%
'建立ADO连接'
'数据库 需设置 绝对路径'
set conn = Server.CreateObject("ADODB.Connection")
conn.Provider = "Microsoft.Jet.OLEDB.4.0"
conn.Open "D:\inetpub\wwwroot\data.mdb"
%>

<%
'创建ADO SQL 记录集'
set rs=Server.CreateObject("ADODB.recordset")
rs.Open "select title, content, created_date from notepad", conn
%>

<!DOCTYPE html>
<html>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<head>
    <title>index</title>
    <style type="text/css">
        table.gridtable {
            font-family: verdana,arial,sans-serif;
            font-size:11px;
            color:#333333;
            border-width: 1px;
            border-color: #666666;
            border-collapse: collapse;
        }
        table.gridtable th {
            border-width: 1px;
            padding: 8px;
            border-style: solid;
            border-color: #666666;
            background-color: #dedede;
        }
        table.gridtable td {
            border-width: 1px;
            padding: 8px;
            border-style: solid;
            border-color: #666666;
            background-color: #ffffff;
        }
    </style>
</head>
<body>

    <form method="POST" action="add.asp">
        <table class="gridtable">
            <tr>
                <td><label>标题</label></td>
                <td><input name="title" type="text"></td>
            </tr>
            <tr>
                <td><label>内容</label></td>
                <td><textarea rows="4" name="content"></textarea></td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <input naem="reset" type="reset" value="重置">
                    <input name="submit" type="submit" value="添加">
                </td>
            </tr>
        </table>
    </form>
    <br><hr><br>
    <table class="gridtable">
      <tr>
      <%for each x in rs.Fields
        Response.write("<th>" & x.name & "</th>")
      next%>
      </tr>
      <%do until rs.EOF%>
        <tr>
        <%for each x in rs.Fields%>
          <td><%Response.write(x.value)%></td>
        <%next
        rs.MoveNext%>
        </tr>
      <%loop
      rs.close
      conn.close%>
    </table>
</body>
</html>

2、add.asp

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%Session.CodePage = 65001%>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<%
    '建立ADO连接'
    '数据库 需设置 绝对路径'
    set conn = Server.CreateObject("ADODB.Connection")
    conn.Provider = "Microsoft.Jet.OLEDB.4.0"
    conn.Open "D:\inetpub\wwwroot\data.mdb"

    sql="INSERT INTO notepad (title, content)"
    sql=sql & " VALUES "
    sql=sql & "('" & Request.Form("title") & "',"
    sql=sql & "'" & Request.Form("content") & "')"
    on error resume next
    conn.Execute sql,recaffected
    if err<>0 then
        Response.Write(sql)
          Response.Write("<br><font color='#A52A2A'><strong>执行失败!</strong></font>")
    else 
        Response.Write(sql)
        Response.Write("<br><font color='#00FF7F' bol><strong>已执行,并添加至数据库!</strong></font>")
        Response.Redirect "index.asp"
    end if
    conn.close
%>
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档