asp代码,添加记录到数据库,问题!

网上找的代码,改了一下,但不太正常,望高手指点!从另一页面提交数据,以下是处理页,提交一两条记录的时候,还可以,多一点,就错误,显示对象关闭时不允许操作<%xm=Requ... 网上找的代码,改了一下,但不太正常,望高手指点!从另一页面提交数据,以下是处理页,提交一两条记录的时候,还可以,多一点,就错误,显示对象关闭时不允许操作
<%
xm=Request.Form("xm")'值为"aaa,bbb,ccc",下面的也是一样.
yw=Request.Form("yw")
sx=Request.Form("sx")
en=Request.Form("en")
wl=Request.Form("wl")
zz=Request.Form("zz")
ls=Request.Form("ls")
zf=Request.Form("zf")
pq=Request.Form("pq")

xm=SPLIT(xm,",")'从","处分割为aaa bbb ccc
for i=0 to ubound(xm)
xm(i)=xm(i)
next
yw=SPLIT(yw,",")
for i=0 to ubound(yw)
yw(i)=yw(i)
next
sx=SPLIT(sx,",")
for i=0 to ubound(sx)
sx(i)=sx(i)
next
en=SPLIT(en,",")'从","处分割为aaa bbb ccc
for i=0 to ubound(en)
en(i)=en(i)
next
wl=SPLIT(wl,",")
for i=0 to ubound(wl)
wl(i)=wl(i)
next
zz=SPLIT(zz,",")
for i=0 to ubound(zz)
zz(i)=zz(i)
next
ls=SPLIT(ls,",")'从","处分割为aaa bbb ccc
for i=0 to ubound(ls)
ls(i)=ls(i)
next
zf=SPLIT(zf,",")
for i=0 to ubound(zf)
zf(i)=zf(i)
next
pq=SPLIT(pq,",")
for i=0 to ubound(pq)
pq(i)=pq(i)
next
for i=0 to ubound(xm)
if yw(i)<>"" or xm(i)<>"" then
dim rs
dim sql
set rs = server.createobject("adodb.recordset")
sql = "select * from tabletemp where [name]='"&trim(xm(i))&"'"
rs.open sql,conn,1,3
if not rs.recordcount=0 then
response.write i&"'"&trim(xm(i))&"'此号码已存在,请重新输入"&"<br>"
else
set rs = server.createobject("adodb.recordset")
sql="insert into tabletemp (name,Chinese,Math,English,wuli,zhengzi,lishi,zong,ping) values ('"&trim(xm(i))&"',"&trim(yw(i))&","&trim(sx(i))&","&trim(en(i))&","&trim(wl(i))&","&trim(zz(i))&","&trim(ls(i))&","&trim(zf(i))&","&trim(pq(i))&")"
'此处可这样加入一个SQL语句进行数据库录入处理
conn.execute sql
rs.Open sql,conn,1,3
rs.update
%>
<%
end if
end if
next
%>
<%
rs.close
set rs=nothing
conn.close
set conn=nothing
%>
谢谢各位,还是出错了!显示的是insert into 语句语法错误!真搞不懂哦!能不能再帮帮忙???
展开
 我来答
百度网友bd6cbf3de
2008-11-15 · TA获得超过914个赞
知道小有建树答主
回答量:666
采纳率:0%
帮助的人:796万
展开全部
xm=SPLIT(xm,",")'从","处分割为aaa bbb ccc 是已经给xm数组赋值,后面三句可以去掉,后面也一样
for i=0 to ubound(xm)
xm(i)=xm(i)
next

<%
xm=Request.Form("xm")'值为"aaa,bbb,ccc",下面的也是一样.
yw=Request.Form("yw")
sx=Request.Form("sx")
en=Request.Form("en")
wl=Request.Form("wl")
zz=Request.Form("zz")
ls=Request.Form("ls")
zf=Request.Form("zf")
pq=Request.Form("pq")

xm=SPLIT(xm,", ")'从","处分割为aaa bbb ccc 注:如果在","的逗号后加一个空格,后面用到xm(i)时也可以不用trim(),不过用也可以,更安全,因为你从former得到的数据实际上是aaa, bbb, ccc,逗号后有一个空格
yw=SPLIT(yw,",")
sx=SPLIT(sx,",")
en=SPLIT(en,",")'从","处分割为aaa bbb ccc
wl=SPLIT(wl,",")
zz=SPLIT(zz,",")
ls=SPLIT(ls,",")'从","处分割为aaa bbb ccc
zf=SPLIT(zf,",")
pq=SPLIT(pq,",")

for i=0 to ubound(xm)
if yw(i)<>"" or xm(i)<>"" then
dim rs
dim sql
set rs = server.createobject("adodb.recordset")
sql = "select * from tabletemp where [name]='"&trim(xm(i))&"'"
rs.open sql,conn,1,3
if rs.recordcount<>0 then
response.write i&"'"&trim(xm(i))&"'此号码已存在,请重新输入"&"<br>"
else
'把这句去掉,rs被重复的定义,这里没有必要set rs = server.createobject("adodb.recordset")
sql2="insert into tabletemp (name,Chinese,Math,English,wuli,zhengzi,lishi,zong,ping) values ('"&trim(xm(i))&"',"&trim(yw(i))&","&trim(sx(i))&","&trim(en(i))&","&trim(wl(i))&","&trim(zz(i))&","&trim(ls(i))&","&trim(zf(i))&","&trim(pq(i))&")"
'此处可这样加入一个SQL语句进行数据库录入处理
conn.execute sql2
'把这句去掉rs.Open sql,conn,1,3
'把这句去掉rs.update

end if
rs.close
end if
next

set rs=nothing
conn.close
set conn=nothing
%>
璩安志05H
2008-11-15 · TA获得超过252个赞
知道小有建树答主
回答量:504
采纳率:0%
帮助的人:0
展开全部
要先打开conn 要么你前面的操作把他给关闭了
set conn=server.createobject("adodb.connection")
dbpath=server.mappath("×。mdb")
conn.open "driver={microsoft access driver (*.mdb)};dbq="&dbpath&";username=;password=liuzhen"
.........
下面就可以操作了

set rs=server.createobject("adodb.recordset")
sqlcmd="select * from ..... "
rs.open sqlcmd,conn,3,2,1
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
芝麻部落
2008-11-15 · TA获得超过452个赞
知道小有建树答主
回答量:287
采纳率:0%
帮助的人:155万
展开全部
set rs = server.createobject("adodb.recordset")
sql = "select * from tabletemp where [name]='"&trim(xm(i))&"'"
rs.open sql,conn,1,3
if not rs.recordcount=0 then
response.write i&"'"&trim(xm(i))&"'此号码已存在,请重新输入"&"<br>"
else
set rs = server.createobject("adodb.recordset")
sql="insert into tabletemp (name,Chinese,Math,English,wuli,zhengzi,lishi,zong,ping) values ('"&trim(xm(i))&"',"&trim(yw(i))&","&trim(sx(i))&","&trim(en(i))&","&trim(wl(i))&","&trim(zz(i))&","&trim(ls(i))&","&trim(zf(i))&","&trim(pq(i))&")"
'此处可这样加入一个SQL语句进行数据库录入处理
conn.execute sql
rs.Open sql,conn,1,3
rs.update

这个位置上看rs被重复的定义了,应该一个rs,一个rs2
改成这样
set rs = server.createobject("adodb.recordset")
sql = "select * from tabletemp where [name]='"&trim(xm(i))&"'"
rs.open sql,conn,1,3
if not rs.recordcount=0 then
response.write i&"'"&trim(xm(i))&"'此号码已存在,请重新输入"&"<br>"
else
set rs2 = server.createobject("adodb.recordset")
sql2="insert into tabletemp (name,Chinese,Math,English,wuli,zhengzi,lishi,zong,ping) values ('"&trim(xm(i))&"',"&trim(yw(i))&","&trim(sx(i))&","&trim(en(i))&","&trim(wl(i))&","&trim(zz(i))&","&trim(ls(i))&","&trim(zf(i))&","&trim(pq(i))&")"
'此处可这样加入一个SQL语句进行数据库录入处理
conn.execute sql2
rs2.Open sql2,conn,1,3
rs2.update
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
binsen11
2008-11-15 · 超过39用户采纳过TA的回答
知道小有建树答主
回答量:299
采纳率:0%
帮助的人:176万
展开全部
我也来改改!主要问题时rs重复了,关闭rs(rs.close )要放在for next内

从最后那个for next改起

改后的代码:
-------------------------------------------
dim rs
dim sql
set rs = server.createobject("adodb.recordset")

for i=0 to ubound(xm)
if yw(i)<>"" or xm(i)<>"" then

sql = "select * from tabletemp where [name]='"&trim(xm(i))&"'"
rs.open sql,conn,1,3

if not rs.recordcount=0 then
response.write i&"'"&trim(xm(i))&"'此号码已存在,请重新输入"&"<br>"
else
sql="insert into tabletemp (name,Chinese,Math,English,wuli,zhengzi,lishi,zong,ping) values ('"&trim(xm(i))&"',"&trim(yw(i))&","&trim(sx(i))&","&trim(en(i))&","&trim(wl(i))&","&trim(zz(i))&","&trim(ls(i))&","&trim(zf(i))&","&trim(pq(i))&")"
'此处可这样加入一个SQL语句进行数据库录入处理
conn.execute sql
rs.Open sql,conn,1,3
rs.update
%>
<%
end if
rs.close

end if
next
%>
<%
set rs=nothing
conn.close
set conn=nothing
%>
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式