请求帮助,关于asp的 一个字段数据同时写入两个表内
<!--#includefile="../data/Conn.asp"--><!--#includefile="AdminMain.asp"--><metahttp-eq...
<!--#include file="../data/Conn.asp" -->
<!--#include file="AdminMain.asp" -->
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<%
dim UserId : UserId=request.Form("id")
dim Name : Name=request.Form("Name")
dim danganhao : danganhao=request.Form("danganhao")
dim changqu : changqu=request.Form("changqu")
dim bumen : bumen=request.Form("bumen")
dim gangwei : gangwei=request.Form("gangwei")
dim yuanbumen : yuanbumen=request.Form("yuanbumen")
dim yuangangwei : yuangangwei=request.Form("yuangangwei")
dim diaodongdate : diaodongdate=request.Form("diaodongdate")
dim ddyy : ddyy=request.Form("ddyy")
dim Message : Message=""
if Name="" then
Message=Message&"姓名不能为空!\n"
end if
if danganhao="" then
Message=Message&"生日不能为空!\n"
end if
if Message<>"" then
response.write("<script>alert('"&Message&"');history.go(-1);</script>")
response.End()
end if
SQLStr="select top 1 * from yuangong where id="&UserId
set rs=conn.execute(sqlstr)
Rs("Name")=Name
Rs("danganhao")=danganhao
Rs("changqu")=changqu
Rs("bumen")=bumen
Rs("gangwei")=gangwei
%>
<%
dim rs2
set rs2=server.createobject("adodb.recordset")
rs2.open "select * from [diaodong]"
Rs2.Open SQLStr,Conn,1,3
rs2.addnew
Rs2("Name")=Name
Rs2("danganhao")=danganhao
Rs2("changqu")=changqu
Rs2("bumen")=bumen
Rs2("gangwei")=gangwei
Rs("yuanbumen")=yuanbumen
Rs("yuangangwei")=yuangangwei
Rs("diaodongdate")=diaodongdate
Rs("ddyy")=ddyy
Rs2.Update
Rs2.Close
%>
<%
response.write("<script>alert('添加成功!');window.location='AdminUserList.asp';</script>")
%>
<!--#include file="../data/ConnClose.asp" -->
就是上面这段代码。我写的有错,怎么写才好呢?
ADODB.Recordset 错误 '800a0e7d'
连接无法用于执行此操作。在此上下文中它可能已被关闭或无效。
/admin/AdmindiaodongUser2.asp,行 46 展开
<!--#include file="AdminMain.asp" -->
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<%
dim UserId : UserId=request.Form("id")
dim Name : Name=request.Form("Name")
dim danganhao : danganhao=request.Form("danganhao")
dim changqu : changqu=request.Form("changqu")
dim bumen : bumen=request.Form("bumen")
dim gangwei : gangwei=request.Form("gangwei")
dim yuanbumen : yuanbumen=request.Form("yuanbumen")
dim yuangangwei : yuangangwei=request.Form("yuangangwei")
dim diaodongdate : diaodongdate=request.Form("diaodongdate")
dim ddyy : ddyy=request.Form("ddyy")
dim Message : Message=""
if Name="" then
Message=Message&"姓名不能为空!\n"
end if
if danganhao="" then
Message=Message&"生日不能为空!\n"
end if
if Message<>"" then
response.write("<script>alert('"&Message&"');history.go(-1);</script>")
response.End()
end if
SQLStr="select top 1 * from yuangong where id="&UserId
set rs=conn.execute(sqlstr)
Rs("Name")=Name
Rs("danganhao")=danganhao
Rs("changqu")=changqu
Rs("bumen")=bumen
Rs("gangwei")=gangwei
%>
<%
dim rs2
set rs2=server.createobject("adodb.recordset")
rs2.open "select * from [diaodong]"
Rs2.Open SQLStr,Conn,1,3
rs2.addnew
Rs2("Name")=Name
Rs2("danganhao")=danganhao
Rs2("changqu")=changqu
Rs2("bumen")=bumen
Rs2("gangwei")=gangwei
Rs("yuanbumen")=yuanbumen
Rs("yuangangwei")=yuangangwei
Rs("diaodongdate")=diaodongdate
Rs("ddyy")=ddyy
Rs2.Update
Rs2.Close
%>
<%
response.write("<script>alert('添加成功!');window.location='AdminUserList.asp';</script>")
%>
<!--#include file="../data/ConnClose.asp" -->
就是上面这段代码。我写的有错,怎么写才好呢?
ADODB.Recordset 错误 '800a0e7d'
连接无法用于执行此操作。在此上下文中它可能已被关闭或无效。
/admin/AdmindiaodongUser2.asp,行 46 展开
4个回答
展开全部
如果第一个表也是插入的话,前面加入rs.addnew(),剩下的楼上已经给你找出来了
像这种连续插入数据库的问题,最好不要创建几个记录集,只用一个就行了,只要前面那个用完了之后用rs.close关掉,接下下面就可以直接rs.open sql,conn了,不用另外再set一个rs2,记得rs在用完之后一定要close掉,不然会浪费资源,也会造成意外错误
像这种连续插入数据库的问题,最好不要创建几个记录集,只用一个就行了,只要前面那个用完了之后用rs.close关掉,接下下面就可以直接rs.open sql,conn了,不用另外再set一个rs2,记得rs在用完之后一定要close掉,不然会浪费资源,也会造成意外错误
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你先运行一下 提示你哪个地方出错 你再说一下 让我看看 这样找真不还找 楼下的回答很好 推荐 数据库不能访问了 你是不是前面的把他关了 或者使用时没有开
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用insert into语句试试
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
仔细 看看你的代码!
<!--#include file="../data/Conn.asp" -->
<!--#include file="AdminMain.asp" -->
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<%
dim UserId : UserId=request.Form("id")
dim Name : Name=request.Form("Name")
dim danganhao : danganhao=request.Form("danganhao")
dim changqu : changqu=request.Form("changqu")
dim bumen : bumen=request.Form("bumen")
dim gangwei : gangwei=request.Form("gangwei")
dim yuanbumen : yuanbumen=request.Form("yuanbumen")
dim yuangangwei : yuangangwei=request.Form("yuangangwei")
dim diaodongdate : diaodongdate=request.Form("diaodongdate")
dim ddyy : ddyy=request.Form("ddyy")
dim Message : Message=""
if Name="" then
Message=Message&"姓名不能为空!\n"
end if
if danganhao="" then
Message=Message&"生日不能为空!\n"
end if
if Message<>"" then
response.write("<script>alert('"&Message&"');history.go(-1);</script>")
response.End()
end if
SQLStr="select top 1 * from yuangong where id="&UserId
'set rs=conn.execute(sqlstr) 改:
set rs=server.createobject("adodb.recordset")
rs.open SQLStr,conn,1,3
Rs("Name")=Name
Rs("danganhao")=danganhao
Rs("changqu")=changqu
Rs("bumen")=bumen
Rs("gangwei")=gangwei
'加上下面两句
rs.update
rs.close
%>
<%
dim rs2
set rs2=server.createobject("adodb.recordset")
rs2.open "select * from [diaodong]"
Rs2.Open SQLStr,Conn,1,3
rs2.addnew
Rs2("Name")=Name
Rs2("danganhao")=danganhao
Rs2("changqu")=changqu
Rs2("bumen")=bumen
Rs2("gangwei")=gangwei
Rs("yuanbumen")=yuanbumen
Rs("yuangangwei")=yuangangwei
Rs("diaodongdate")=diaodongdate
Rs("ddyy")=ddyy
Rs2.Update
Rs2.Close
%>
<%
response.write("<script>alert('添加成功!');window.location='AdminUserList.asp';</script>")
%>
<!--#include file="../data/ConnClose.asp" -->
另外,如果代码有错,下次提问记得把错误提示一起贴上来!
在代码最前加一句:<%conn.open connstr%>
<!--#include file="../data/Conn.asp" -->
<!--#include file="AdminMain.asp" -->
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<%
dim UserId : UserId=request.Form("id")
dim Name : Name=request.Form("Name")
dim danganhao : danganhao=request.Form("danganhao")
dim changqu : changqu=request.Form("changqu")
dim bumen : bumen=request.Form("bumen")
dim gangwei : gangwei=request.Form("gangwei")
dim yuanbumen : yuanbumen=request.Form("yuanbumen")
dim yuangangwei : yuangangwei=request.Form("yuangangwei")
dim diaodongdate : diaodongdate=request.Form("diaodongdate")
dim ddyy : ddyy=request.Form("ddyy")
dim Message : Message=""
if Name="" then
Message=Message&"姓名不能为空!\n"
end if
if danganhao="" then
Message=Message&"生日不能为空!\n"
end if
if Message<>"" then
response.write("<script>alert('"&Message&"');history.go(-1);</script>")
response.End()
end if
SQLStr="select top 1 * from yuangong where id="&UserId
'set rs=conn.execute(sqlstr) 改:
set rs=server.createobject("adodb.recordset")
rs.open SQLStr,conn,1,3
Rs("Name")=Name
Rs("danganhao")=danganhao
Rs("changqu")=changqu
Rs("bumen")=bumen
Rs("gangwei")=gangwei
'加上下面两句
rs.update
rs.close
%>
<%
dim rs2
set rs2=server.createobject("adodb.recordset")
rs2.open "select * from [diaodong]"
Rs2.Open SQLStr,Conn,1,3
rs2.addnew
Rs2("Name")=Name
Rs2("danganhao")=danganhao
Rs2("changqu")=changqu
Rs2("bumen")=bumen
Rs2("gangwei")=gangwei
Rs("yuanbumen")=yuanbumen
Rs("yuangangwei")=yuangangwei
Rs("diaodongdate")=diaodongdate
Rs("ddyy")=ddyy
Rs2.Update
Rs2.Close
%>
<%
response.write("<script>alert('添加成功!');window.location='AdminUserList.asp';</script>")
%>
<!--#include file="../data/ConnClose.asp" -->
另外,如果代码有错,下次提问记得把错误提示一起贴上来!
在代码最前加一句:<%conn.open connstr%>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询