平时做技术实践时,很多问题不是概念不会,而是细节没串起来。拿“asp批量添加修改删除操作示例代码”来说,它看着像小点,放到项目里常会牵出环境、配置、兼容性和维护成本。下面按实际采用顺序,把思路、关键写法和容易踩坑的地方讲清楚,便于大家直接对照操作。
核心代码:
asp批量添加修改删除操作示例
<%
if request.Form("op")="update" then'表单提交
ids=request.Form("ids")
if ids<>"" then
response.Write "要删除的数据id集合:"&ids&"
"
'=========数据库删除操作 conn.execute("delete from xxx where id in("&ids&")")'自己注意做安全验证,假定id为数字集合,自己正则RegExp判断有效性,pattern为^\d+(,\d+)*$
end if
rows=request.Form("name").count'提交的数据行数据,包括添加/修改的
for i=1 to rows'遍历每行数据
id=request.Form("id").item(i)&""
name=request.Form("name").item(i)
sex=request.Form("sex").item(i)
age=request.Form("age").item(i)
addr=request.Form("addr").item(i)
if id<>"" then'修改操作,如果id为数字加isnumeric判断
response.Write "要修改数据行:"&id&"|"&name&"|"&sex&"|"&age&"|"&addr&"
"
'修改操作
else'添加操作
response.Write "要添加数据行:"&name&"|"&sex&"|"&age&"|"&addr&"
"
'添加操作
end if
next
end if
%>

