1. 论坛系统升级为Xenforo,欢迎大家测试!
    排除公告

每个ASP程序员必备的知识

本帖由 tonh56362012-04-16 发布。版面名称:后端开发

  1. tonh5636

    tonh5636 New Member

    注册:
    2012-03-24
    帖子:
    243
    赞:
    0
    数据库连接:
    <;%
    set conn=server.createobject("adodb.connection")
    conn.open "driver={microsoft access driver (*.mdb)};dbq="&;server.mappath("数据库名")
    %>;

    打开数据库:

    exec="select * from 数据库表"
    set rs=server.createobject("adodb.recordset")
    rs.open exec,conn,1,1
    参数1,1为读取
    读取内容格式:<;%=rs("字段")%>;
    添加记录处理程序:

    <;%
    set conn=server.createobject("adodb.connection")
    conn.open "driver={microsoft access driver (*.mdb)};dbq="&;server.mappath("数据库名")
    name=request.form("字段") name,tel,message为提交表单所设置的字段值
    tel=request.form("字段")
    message=request.form("字段")
    exec="insert into 表名(字段)values(‘;"+字段+"‘;)" 多个用逗号隔开
    conn.execute exec 使用execute提交
    conn.close
    set conn=nothing
    %>;

    搜索处理程序:

    <;%
    name=request.form("字段") name,tel为提交表单所设置的字段值
    tel=request.form("字段")
    set conn=server.createobject("adodb.connection")
    conn.open "driver={microsoft access driver (*.mdb)};dbq="&;server.mappath("数据库名")
    exec="select * from 表 where name=‘;"+字段+"‘; and tel="+字段
    set rs=server.createobject("adodb.recordset")
    rs.open exec,conn,1,1
    %>;

    ‘;页面搜索到的内容导出来

    <;%
    do while not rs.eof
    %>;<;tr>;
    <;td>;<;%=rs("name")%>;<;/td>;
    <;td>;<;%=rs("tel")%>;<;/td>;
    <;td>;<;%=rs("time")%>;<;/td>;
    <;/tr>;
    <;%
    rs.movenext
    loop
    %>;

    删除记录处理程序:

    <;%
    set conn=server.createobject("adodb.connection")
    conn.open "driver={microsoft access driver (*.mdb)};dbq="&;server.mappath("数据库名")
    exec="delete * from 表名 where 编号="&;request.form("id")
    conn.execute exec
    %>;

    修改记录处理程序:

    <;%
    set conn=server.createobject("adodb.connection")
    conn.open "driver={microsoft access driver (*.mdb)};dbq="&;server.mappath("数据库名")
    exec="select * from 表名 where 编号="&;request.form("id")
    set rs=server.createobject("adodb.recordset")
    rs.open exec,conn,1,3 ‘;1,3为修改意思
    rs("name")=request.form("字段") ‘;name,tel,message为提交表单所设置的字段值
    rs("tel")=request.form("字段")
    rs("message")=request.form("字段")
    rs.update
    rs.close
    set rs=nothing
    conn.close
    set conn=nothing
    %>;


    修改记录执行程序:输入ID号页面>;>;>;导出相对应ID数据>;>;>;>;>;>;直接修改的处理程序
    后台登陆处理程序例子:


    <;%
    dim name,password
    name=request.form("name")
    password=request.form("password")
    dim exec,conn,rs
    exec="select *from 表名 where(name=‘;"&;字段&;"‘; and password=‘;"&;字段&;"‘;)"
    set conn=server.createobject("adodb.connection")
    conn.open "driver={microsoft access driver (*.mdb)};dbq="&;server.mappath("数据库名")
    set rs=server.createobject("adodb.recordset")
    rs.open exec,conn
    if not rs.eof then
    rs.Close
    conn.Close
    session("checked")="yes"
    session("check")="right"
    response.Redirect "index.asp"
    else
    session("checked")="no"
    session("check")="wrong"
    response.Redirect "login.asp"
    end if
    %>;

    每个后台页面加上:

    <;%if not session("checked")="yes" then ‘;session里面定义一个checked字符串变量
    response.Redirect "login.asp"
    else
    %>;
     
  2. 落幕1

    落幕1 New Member

    注册:
    2012-05-01
    帖子:
    64
    赞:
    0
    每个后台页面加上
     
  3. qqzm

    qqzm New Member

    注册:
    2013-07-01
    帖子:
    30
    赞:
    0
    支持一下!
     
  4. ﹏譆揂嶼妳ゞ

    注册:
    2017-08-28
    帖子:
    132
    赞:
    0
    新手上路,过来学习下~
     
  5. 和商投资

    和商投资 Member

    注册:
    2017-08-22
    帖子:
    160
    赞:
    0
    果然要学的东西还多着