zoukankan      html  css  js  c++  java
  • asp 调用Recordset对象操作数据库

         前面讲到了用command对象对数据库的操作,完成了增删查改,也可以使用ado的另外一个对象Recordset来完成对数据库的操作:

        首先要创建RecordSet

       

    View Code
    <%
       set conn=server.CreateObject("adodb.connection")
       connstr="provider=sqloledb;data source=(local)\sky;initial catalog=lszx;user id=sa;password=sa;"
       conn.open connstr
       set rs=server.CreateObject("adodb.RecordSet")
       strsql="select * from tb_person"
       rs.open strsql,conn,2,3  
    %>

     技巧:查询就是1,1

             增删改就用1,3或2,3(1 执行操作后记录集里只保存当前记录,2 是全部 )

       其次就可以调用RecordSet的方法(如AddNew,update,delete)

      AddNew

    View Code
        rs.addnew()
        rs("userName")=request("txt_username")
       rs("sex")=request("txt_sex")
       rs("age")=request("txt_age")
       rs("aihao")=request("txt_aihao")
       rs.update  ‘更新记录集

    update

    View Code
     rs("username")=request("txt_username")
       rs("sex")=request("txt_sex")
       rs("age")=request("txt_age")
       rs("aihao")=request("txt_aihao")
       rs.update
      response.Write("<script language='javascript'>alert('数据修改成功!');location.href='user_list2.asp'</script>")  

     循环读取数据

    while not rs.eof

    rs("")

    rs.movenext
     wend

    记录数

    rs.RecordCount

    多思考,多创新,才是正道!
  • 相关阅读:
    设计模式读书笔记
    effective_c++(第三版)读书笔记
    CS-Notes 操作系统读书笔记
    数据库笔记
    后台开发核心技术与应用读书笔记
    python3.7安装numpy pandas失败的处理方案
    线段树模板
    KMP算法
    离散实验——欧拉图的判定和应用
    堆排序算法及其实现
  • 原文地址:https://www.cnblogs.com/shuang121/p/2231190.html
Copyright © 2011-2022 走看看