| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 669 人关注过本帖
标题:asp记录集对象的
只看楼主 加入收藏
陆嘉文
Rank: 1
来 自:江西
等 级:新手上路
帖 子:96
专家分:6
注 册:2011-11-10
结帖率:76.92%
收藏
 问题点数:0 回复次数:2 
asp记录集对象的
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%option explicit%>
<!--#include file="conn.asp"-->
<%
    dim str1,str2,str3,str4,rs
    str1=trim(request.Form("文章类别"))
    str2=trim(request.Form("文章作者"))
    str3=trim(request.Form("文章主题"))
    str4=trim(request.Form("文章内容"))
    '判断
    if request.querystring("action")<>"" then
        if str1<>"" and str2<>"" and str3<>"" and str4<>"" then
             Set rs=Server.CreateObject("ADODB.Recordset")
    sql="insert into tab_article(Aclass,Aauthor,Atitle,Acontent) values("&str1&",'"&str2&"','"&str3&"','"&str4&"')"
        rs.open sql,conn,1,3
    end if
    end if
    rs.close
    set rs=nothing

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
<html xmlns="http://www.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
<!--
.button {width:60px;
margin-right:10px;}
-->
</style>
</head>

<body>
<p style="font-weight:bolder;" align="center">添加文章</p>
<form method="post" action="?action=true"/>
<table width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#000000">
  <tr>
    <td width="30%" height="30" bgcolor="#FFFFFF">文章类别:</td>
    <td height="30" bgcolor="#FFFFFF">
        <select name="文章类别">
        <option selected="selected">选择类别</option>
    <%
            dim rs_new,sql
            set rs_new=server.CreateObject("adodb.recordset")
            sql="select * from tab_article_class"
            rs_new.open sql,conn,1,1
            do while not rs_new.eof
    %>
   
            <option value="<%=rs_new("id")%>"><%=rs_new("Acname")%></option>
     
        <%
        rs_new.movenext
        loop
        rs_new.close        
        set rs_new=nothing

        conn.close
        set conn=nothing

        %>
           </select>
    </td>
  </tr>
  <tr>
    <td height="30" bgcolor="#FFFFFF">文章作者:</td>
    <td height="30" bgcolor="#FFFFFF"><input type="text" name="文章作者" size="25"/></td>
  </tr>
  <tr>
    <td height="30" bgcolor="#FFFFFF">文章主题:</td>
    <td height="30" bgcolor="#FFFFFF"><input type="text" name="文章主题" size="25"/></td>
  </tr>
  <tr>
    <td height="30" bgcolor="#FFFFFF">文章内容:</td>
    <td height="30" bgcolor="#FFFFFF"><textarea name="文章内容" cols="40" rows="6">
            
        </textarea></td>
  </tr>
  <tr>
    <td height="30" colspan="2" align="center" bgcolor="#FFFFFF"><input type="submit" name="提交" value="修改" class="button"/>
    <input type="button" name="返回" value="返回" class="button" onclick="javascript:window.location.href='index_2.asp'" /></td>
  </tr>
</table>
</form>

</body>
</html>为什么总是显示对象关闭,不允许操作,而且我想问一下,代码里面的这句话有错吗?
   sql="insert into tab_article(Aclass,Aauthor,Atitle,Acontent) values("&str1&",'"&str2&"','"&str3&"','"&str4&"')"
        rs.open sql,conn,1,3
搜索更多相关主题的帖子: 主题 option insert action include 
2013-06-05 17:21
yms123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:209
帖 子:12488
专家分:19042
注 册:2004-7-17
收藏
得分:0 
sql="insert into tab_article(Aclass,Aauthor,Atitle,Acontent) values("&str1&",'"&str2&"','"&str3&"','"&str4&"')"
        rs.open sql,conn,1,3
insert语句不要这样执行
sql="insert into tab_article(Aclass,Aauthor,Atitle,Acontent) values("&str1&",'"&str2&"','"&str3&"','"&str4&"')"
conn.execute(sql)
这样才可以因为rs.open只适用于select查询语句返回结果,插入数据库要用con.execute执行insert语句
2013-06-06 11:05
maprincesse
Rank: 2
等 级:论坛游民
威 望:1
帖 子:22
专家分:19
注 册:2013-1-15
收藏
得分:0 
直接set rs=conn.execute("insert into tab_article(Aclass,Aauthor,Atitle,Acontent) values("&str1&",'"&str2&"','"&str3&"','"&str4&"')")
conn.execute 不支持open方法
想用rs.open sql,conn,1,3就得
建立记录集 set rs=server.createobject("adodb.recordset")
建立查询   sql="----------------------------------"
打开查询   rs.open sql,conn,1,3
添加记录   rs.addnew()
这样
2013-06-09 16:06
快速回复:asp记录集对象的
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018907 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved