请帮忙解决个asp批量选择修改数据的问题

时间:2022-01-31 06:47:50
在此先谢谢!
目的:批量有选择的修改数据。
目前问题:只能够修改1个选择,其他的多项选择提示错误:第 1 行: ',' 附近有语法错误
代码:
<!--#include file="../Connections/xinlong.asp" -->
<%
Set rs = Server.CreateObject("ADODB.Recordset")
rs.open"SELECT * FROM ceshi1 ORDER BY id DESC",MM_xinlong_STRING,1,1
%>
<%
Dim Repeatswt__numRows
Dim Repeatswt__index

Repeatswt__numRows = -1
Repeatswt__index = 0
rs_numRows = rs_numRows + Repeatswt__numRows
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="fuxuanxiugai_1.asp">
  <table width="800" border="1" cellpadding="0" cellspacing="0">
    <tr>
      <td align="center">选择</td>
      <td align="center">ID</td>
      <td align="center">名称</td>
      <td align="center">数量</td>
      <td align="center">水票</td>
      <td align="center">备注</td>
    </tr>
    <% 
While ((Repeatswt__numRows <> 0) AND (NOT rs.EOF)) 
%><tr>
      <td align="center"><label>
        <input type="checkbox" name="checkbox" value="<%=rs("id")%>" /><%=rs("id")%>
      </label></td>
      <td align="center"><label>
        <input name="id" type="text" id="id" value="<%=rs("id")%>" />
      </label></td>
      <td align="center"><input name="mingcheng<%=rs("id")%>" type="text" id="mingcheng<%=rs("id")%>" value="<%=rs("mingcheng")%>" /></td>
      <td align="center"><input name="shuliang<%=rs("id")%>" type="money" id="shuliang<%=rs("id")%>" value="<%=rs("shuliang")%>" /></td>
      <td align="center"><input name="shuipiao<%=rs("id")%>" type="money" id="shuipiao<%=rs("id")%>" value="<%=rs("shuipiao")%>" /></td>
      <td align="center"><input name="beizhu<%=rs("id")%>" type="text" id="beizhu<%=rs("id")%>" value="<%=rs("beizhu")%>" /></td>
    </tr>
<% 
  Repeatswt__index=Repeatswt__index+1
  Repeatswt__numRows=Repeatswt__numRows-1
  rs.MoveNext()
Wend
%>
    <tr>
      <td align="center">&nbsp;</td>
      <td align="center"><label>
        <input type="submit" name="Submit" value="提交" />
      </label></td>
      <td align="center">&nbsp;</td>
      <td align="center">&nbsp;</td>
      <td align="center">&nbsp;</td>
      <td align="center">&nbsp;</td>
    </tr>
  </table>
</form>
</body>
</html>
传递到下一页代码
<!--#include file="../Connections/xinlong.asp" -->
<%
Set rs = Server.CreateObject("ADODB.Recordset")
rs.open"SELECT * FROM ceshi1 ORDER BY id DESC",MM_xinlong_STRING,1,1
%>
<%
sss=request("checkbox")
'sss的值就是选中的值,例如这样的: 1,3,5,然后使用split得到所有ID,再用循环处理
aa=split(sss,",")

for t=0 to ubound(aa)
rec_id=aa(t)'这个就是单个的ID
'这个是修改数据库数据
set rswbdx=server.CreateObject("adodb.recordset")
rswbdx.open"UPDATE ceshi1 SET mingcheng = '"&Request("mingcheng"&rec_id&"")&"',shuipiao = "&Request("shuipiao"&rec_id&"")&",shuliang = "&Request("shuliang"&rec_id&"")&",beizhu = '"&Request("beizhu"&rec_id&"")&"' WHERE id ='"&rec_id&"'",MM_xinlong_STRING,1,1
Set rswbdx = Nothing

next
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<a href="fuxuanxiugai.asp">管理成功返回
</a>
</body>

</html>
请问如何修改。
谢谢?

7 个解决方案

#1


提交的数据有问题吧,自己打印sql出来看就知道了。如你的shuipiao,shuliang是数字,没填写肯定会报错了
for t=0 to ubound(aa)
  rec_id=trim(aa(t))'这个就是单个的ID
  if rec_id<>"" then'加不为空判断
    ''''''''''''''打印sql
    response.Write "UPDATE ceshi1 SET mingcheng = '"&Request("mingcheng"&rec_id&"")&"',shuipiao = "&Request("shuipiao"&rec_id&"")&",shuliang = "&Request("shuliang"&rec_id&"")&",beizhu = '"&Request("beizhu"&rec_id&"")&"' WHERE id ='"&rec_id&"'"
    set rswbdx=server.CreateObject("adodb.recordset")
    rswbdx.open"UPDATE ceshi1 SET mingcheng = '"&Request("mingcheng"&rec_id&"")&"',shuipiao = "&Request("shuipiao"&rec_id&"")&",shuliang = "&Request("shuliang"&rec_id&"")&",beizhu = '"&Request("beizhu"&rec_id&"")&"' WHERE id ='"&rec_id&"'",MM_xinlong_STRING,1,1
    Set rswbdx = Nothing
  end if
next

#2


好,我试试看,谢谢

#3


还是
Microsoft OLE DB Provider for SQL Server 错误 '80040e14'

第 1 行: ',' 附近有语法错误。

/ceshi/fuxuanxiugai_1.asp,行 16

会不会是第一页的多选框有问题?

#4


显示上看,能够循环,但是除第一条外没有循环的 数值
UPDATE ceshi1 SET mingcheng = '5fgfh',shuipiao = 0,shuliang = 0,beizhu = '5dfgdfhgjdg' WHERE id =5UPDATE ceshi1 SET mingcheng = '',shuipiao = ,shuliang = ,beizhu = '' WHERE id = 4
Microsoft OLE DB Provider for SQL Server 错误 '80040e14'

第 1 行: ',' 附近有语法错误。

/ceshi/fuxuanxiugai_1.asp,行 22

#5


rec_id= trim(aa(t))'这个就是单个的ID

你trim了没有,我记得checkbox提交的值逗号之间是有空格的,要去掉,看你输出的sql语句也是存在空格,要去掉空格,要不name值就对不上了

#6


引用 5 楼 showbo 的回复:
rec_id= trim(aa(t))'这个就是单个的ID

你trim了没有,我记得checkbox提交的值逗号之间是有空格的,要去掉,看你输出的sql语句也是存在空格,要去掉空格,要不name值就对不上了


hao好了,谢谢!

#7


引用 6 楼 qjx18608777156 的回复:
Quote: 引用 5 楼 showbo 的回复:

rec_id= trim(aa(t))'这个就是单个的ID

你trim了没有,我记得checkbox提交的值逗号之间是有空格的,要去掉,看你输出的sql语句也是存在空格,要去掉空格,要不name值就对不上了


hao好了,谢谢!
记得结贴。

#1


提交的数据有问题吧,自己打印sql出来看就知道了。如你的shuipiao,shuliang是数字,没填写肯定会报错了
for t=0 to ubound(aa)
  rec_id=trim(aa(t))'这个就是单个的ID
  if rec_id<>"" then'加不为空判断
    ''''''''''''''打印sql
    response.Write "UPDATE ceshi1 SET mingcheng = '"&Request("mingcheng"&rec_id&"")&"',shuipiao = "&Request("shuipiao"&rec_id&"")&",shuliang = "&Request("shuliang"&rec_id&"")&",beizhu = '"&Request("beizhu"&rec_id&"")&"' WHERE id ='"&rec_id&"'"
    set rswbdx=server.CreateObject("adodb.recordset")
    rswbdx.open"UPDATE ceshi1 SET mingcheng = '"&Request("mingcheng"&rec_id&"")&"',shuipiao = "&Request("shuipiao"&rec_id&"")&",shuliang = "&Request("shuliang"&rec_id&"")&",beizhu = '"&Request("beizhu"&rec_id&"")&"' WHERE id ='"&rec_id&"'",MM_xinlong_STRING,1,1
    Set rswbdx = Nothing
  end if
next

#2


好,我试试看,谢谢

#3


还是
Microsoft OLE DB Provider for SQL Server 错误 '80040e14'

第 1 行: ',' 附近有语法错误。

/ceshi/fuxuanxiugai_1.asp,行 16

会不会是第一页的多选框有问题?

#4


显示上看,能够循环,但是除第一条外没有循环的 数值
UPDATE ceshi1 SET mingcheng = '5fgfh',shuipiao = 0,shuliang = 0,beizhu = '5dfgdfhgjdg' WHERE id =5UPDATE ceshi1 SET mingcheng = '',shuipiao = ,shuliang = ,beizhu = '' WHERE id = 4
Microsoft OLE DB Provider for SQL Server 错误 '80040e14'

第 1 行: ',' 附近有语法错误。

/ceshi/fuxuanxiugai_1.asp,行 22

#5


rec_id= trim(aa(t))'这个就是单个的ID

你trim了没有,我记得checkbox提交的值逗号之间是有空格的,要去掉,看你输出的sql语句也是存在空格,要去掉空格,要不name值就对不上了

#6


引用 5 楼 showbo 的回复:
rec_id= trim(aa(t))'这个就是单个的ID

你trim了没有,我记得checkbox提交的值逗号之间是有空格的,要去掉,看你输出的sql语句也是存在空格,要去掉空格,要不name值就对不上了


hao好了,谢谢!

#7


引用 6 楼 qjx18608777156 的回复:
Quote: 引用 5 楼 showbo 的回复:

rec_id= trim(aa(t))'这个就是单个的ID

你trim了没有,我记得checkbox提交的值逗号之间是有空格的,要去掉,看你输出的sql语句也是存在空格,要去掉空格,要不name值就对不上了


hao好了,谢谢!
记得结贴。