动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
   Asp → 阅读文章

 ASP+ADO实现数据读写简单示例

作者来源: 
阅读 1067 人次 , 2006-4-18 3:22:00 

//showdata.asp
<%@ language="vbscript" codepage="936" %>
 
<html>
    <head>
        <title>[show the data]</title>
       
    </head>
    <body>
    <%
        Application.Lock()
        set dataConnect = Server.CreateObject("ADODB.Connection")
        strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="_
                     &Server.MapPath("db1.mdb")&_
                     ";Persist Security Info=True"
        dataConnect.Open(strConnect)
        if Request.Form("name") <> "" or Request.Form("phone") then
             sqlInsertcmd = "insert into table1(name,phone) values('"_
                            &Request.Form("name")&"','"&Request.Form("phone")&"')"
             dataConnect.Execute(sqlInsertcmd)
        end if
        set dbtabptr = Server.CreateObject("ADODB.Recordset")
        dbtabptr.ActiveConnection = dataConnect
        strSql = "select * from table1"
        dbtabptr.Open(strSql)
        Response.Write("<table width='100%' border='1'>")
        Response.Write("<tr>")
        Response.Write("<th>name</th>")
        Response.Write("<th>phone</th>")
        dbtabptr.MoveFirst()
        do until dbtabptr.EOF
            Response.Write("<tr>")
            Response.Write("<td>")
            Response.Write(dbtabptr("name"))
            Response.Write("</td>")
            Response.Write("<td>")
            Response.Write(dbtabptr("phone"))
            Response.Write("</td>")
            Response.Write("</tr>")
            dbtabptr.MoveNext()
        loop
        Response.Write("</tr>")
        Response.Write("</table>")    
        dataConnect.Close()
        Application.UnLock()
    %>
    <a href="addData.asp">Add a Data to Database</a>   
    </body>
</html>
// addData.asp
<%@ language="vbscript" codepage="936" %>
<html>
    <head>
        <title>[Add data]</title>
    </head>
    <body>
        <form name="adddata" action="showData.asp" method="post">
        <table>
            <tr>
                <td align="right">name:</td>
                <td><input name="name" type="text" /></td>
            </tr>
            <tr>
                <td align="right">phone:</td>
                <td><input name="phone" type="text" /></td>
            </tr>
            <tr>
                <td><input name="submit" type="submit" value="submit" /></td>
                <td><input name="reset" type="reset" value="reset" /></td>
            </tr>
        </table>
        </form>
    </body>
</html>

  
 本文TagsC#  
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:破解XP或者2000的IIS连接数限制
· 下一篇:一个简单的用户登录接口asp实现
· 判断客户端是否支持cookie的脚本!
· 用ASP做一个记事本编缉器(附源码)
· Asp编码优化技巧8则
· 通过数组给您的文件排序
· ASP进阶教程Ⅸ:留言查询功能(一)


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077