| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 759 人关注过本帖
标题:批量添加问题,貌似解决了,大家一起看下是否正确方法。
只看楼主 加入收藏
huangjunyi
Rank: 2
等 级:论坛游民
帖 子:8
专家分:20
注 册:2013-9-25
收藏
 问题点数:0 回复次数:4 
批量添加问题,貌似解决了,大家一起看下是否正确方法。
其中 dim j
for j=kaishi to jieshu 是我要定义的循环批量添加数字想要在product_name和pic上添加循环数字!
接触asp时间不长。大多自学。如果是rs.update方式的我会弄conn.execute "insert into方式的我弄了很长时间不行。还分开获取编号id。看了置顶的帖子(那帖子很强大,粗略看了一下,有时间仔细去看,很实用)
大家一起探讨一下吧。脑很迷糊现在。。
贴上代码,求教!!!
access数据库!

<%
'开始添加商品

id=request("id")
bianhao1=date()
bianhao1=replace(bianhao1, "-", "")
bianhao1=replace(bianhao1, " ", "")
bianhao1=replace(bianhao1, ":", "")
bianhao=request("bianhao")
ifbianhao=request("ifbianhao")
product_name=trim(request("product_name"))
price=request("price")
sprice=request("sprice")
pfprice=request("pfprice")
vprice=request("vprice")
if vprice="" then vprice=""
cprice=request("cprice")
if cprice="" then cprice=""
cbprice=request("cbprice")
if cbprice="" then cbprice="0"
sort_name=request("sort_name")
csort_name=request("csort_name")
cxsort_name=request("cxsort_name")
cysort_name=request("cysort_name")
pro1=request("pro1")
pro2=request("pro2")
pro3=request("pro3")
pro4=request("pro4")
pro5=request("pro5")
pro6=request("pro6")
pro7=request("pro7")
pro8=request("pro8")
pro6_name=request("pro6_name")
pro7_name=request("pro7_name")
info=request("info")
siminfo=replace(request("siminfo"), ">", "&gt;")
siminfo=replace(siminfo, "<", "&lt;")
siminfo=replace(siminfo, "'","’")
if siminfo="" then siminfo="No infomation!"
stj=request("stj")
ytj=request("ytj")
cx=request("cx")
pic=request("pic")
if pic="" then pic="noimages.gif"
cpic=request("cpic")
if cpic="" then cpic="nonegif.gif"
cinfo=request("cinfo")
bzhuang=request("bzhuang")
company=request("company")
brand=request("brand")
zhuangtai=request("zhuangtai")
dim day
day=now()

if request("action")="add" then
'开始检测此产品名是否重复登陆
set rs=server.createobject("ADODB.Recordset")
sql="select * from 56770_product where product_name='"&product_name&"' order by id desc"
rs.open sql, conn, 1, 1
if not(rs.eof or rs.bof)then
        response.write"<SCRIPT language=JavaScript>alert('对不起,您所添加的商品其商品名已经存在, 请核实!');"
response.write"javascript:history.go(-1)</SCRIPT>"
rs.close
set rs=nothing
response.end
end if
'结束检验,添加商品
dim j
for j=kaishi to jieshu
conn.execute "insert into 56770_product (product_name,price, sprice, vprice, cprice,cbprice, pfprice,info, pic, cpic, company, brand, sort_name, csort_name, cxsort_name, cysort_name, cinfo, bzhuang,pro1,pro2,pro3,pro4,pro5,pro6,pro7,pro8,pro6_name,pro7_name,ifbianhao,zhuangtai,siminfo)values('"&product_name&"', "&price&", "&sprice&", "&vprice&", "&cprice&","&cbprice&", "&pfprice&",'"&info&"', '"&pic&"', '"&cpic&"', '"&company&"', '"&brand&"', '"&sort_name&"', '"&csort_name&"', '"&cxsort_name&"', '"&cysort_name&"', '"&cinfo&"', '"&bzhuang&"','"&pro1&"','"&pro2&"','"&pro3&"','"&pro4&"','"&pro5&"','"&pro6&"','"&pro7&"','"&pro8&"','"&pro6_name&"','"&pro7_name&"','"&ifbianhao&"',1,'"&siminfo&"')"
'取得添加商品ID,添加商品编号及推荐促销项目
set rs=server.createobject("ADODB.Recordset")
sql="select * from 56770_product order by id desc"
rs.open sql, conn, 1, 1
id=rs("id")
rs.close
set rs=nothing
if request("ifbianhao")="1" then
bianhao=bianhao1&id
else
bianhao=request("bianhao")
end if
conn.execute "update 56770_product set bianhao='"&bianhao&"' where id=" & id
'判断为何推荐
'if etj="on" then conn.execute "update 56770_product set etj=true where id=" & id
        if cx="on" then conn.execute "update 56770_product set cx=true where id=" & id
        if stj="on" then conn.execute "update 56770_product set stj=true where id=" & id
        if ytj="on" then conn.execute "update 56770_product set ytj=true where id=" & id
        conn.execute "update 56770_product set day=now() where id=" & id
        response.write"<SCRIPT language=JavaScript>alert('商品添加成功 返回继续添加!');"
response.write"javascript:history.go(-2)</SCRIPT>"
response.end
end if
%>

[ 本帖最后由 huangjunyi 于 2013-9-26 10:01 编辑 ]
搜索更多相关主题的帖子: request replace access insert 数据库 
2013-09-25 22:16
huangjunyi
Rank: 2
等 级:论坛游民
帖 子:8
专家分:20
注 册:2013-9-25
收藏
得分:0 
conn.execute "insert into 第一次遇到。基本看不懂。分成写入后获取编号。我甚至不知道next要从哪里入手。搞了一下午。望大家帮忙!!谢谢
2013-09-25 22:21
huangjunyi
Rank: 2
等 级:论坛游民
帖 子:8
专家分:20
注 册:2013-9-25
收藏
得分:0 
回复 2楼 huangjunyi
好像解决了,代码附上大家看看有没有不对的地方!加的地方加红处理方便大家看<%
'开始添加商品
kaishi=request("kaishi")
jieshu=request("jieshu")

id=request("id")
bianhao1=date()
bianhao1=replace(bianhao1, "-", "")
bianhao1=replace(bianhao1, " ", "")
bianhao1=replace(bianhao1, ":", "")
bianhao=request("bianhao")
ifbianhao=request("ifbianhao")
product_name=trim(request("product_name"))
price=request("price")
sprice=request("sprice")
pfprice=request("pfprice")
vprice=request("vprice")
if vprice="" then vprice=""
cprice=request("cprice")
if cprice="" then cprice=""
cbprice=request("cbprice")
if cbprice="" then cbprice="0"
sort_name=request("sort_name")
csort_name=request("csort_name")
cxsort_name=request("cxsort_name")
cysort_name=request("cysort_name")
pro1=request("pro1")
pro2=request("pro2")
pro3=request("pro3")
pro4=request("pro4")
pro5=request("pro5")
pro6=request("pro6")
pro7=request("pro7")
pro8=request("pro8")
pro6_name=request("pro6_name")
pro7_name=request("pro7_name")
info=request("info")
siminfo=replace(request("siminfo"), ">", "&gt;")
siminfo=replace(siminfo, "<", "&lt;")
siminfo=replace(siminfo, "'","’")
if siminfo="" then siminfo="No infomation!"
stj=request("stj")
ytj=request("ytj")
cx=request("cx")
pic=request("pic")
if pic="" then pic="noimages.gif"
cpic=request("cpic")
if cpic="" then cpic="nonegif.gif"
cinfo=request("cinfo")
bzhuang=request("bzhuang")
company=request("company")
brand=request("brand")
zhuangtai=request("zhuangtai")
dim day
day=now()
dim i

if request("action")="add" then
'开始检测此产品名是否重复登陆
set rs=server.createobject("ADODB.Recordset")
sql="select * from 56770_product where product_name='"&product_name&"' order by id desc"
rs.open sql, conn, 1, 1
if not(rs.eof or rs.bof)then
        response.write"<SCRIPT language=JavaScript>alert('对不起,您所添加的商品其商品名已经存在, 请核实!');"
response.write"javascript:history.go(-1)</SCRIPT>"
rs.close
set rs=nothing
response.end
end if
for i=kaishi to jieshu
'结束检验,添加商品
conn.execute "insert into 56770_product (product_name,price, sprice, vprice, cprice,cbprice, pfprice,info, pic, cpic, company, brand, sort_name, csort_name, cxsort_name, cysort_name, cinfo, bzhuang,pro1,pro2,pro3,pro4,pro5,pro6,pro7,pro8,pro6_name,pro7_name,ifbianhao,zhuangtai,siminfo)values('"&product_name&"-"&i&"', "&price&", "&sprice&", "&vprice&", "&cprice&","&cbprice&", "&pfprice&",'"&info&"', '"&pic&"', '"&cpic&"', '"&company&"', '"&brand&"', '"&sort_name&"', '"&csort_name&"', '"&cxsort_name&"', '"&cysort_name&"', '"&cinfo&"', '"&bzhuang&"','"&pro1&"','"&pro2&"','"&pro3&"','"&pro4&"','"&pro5&"','"&pro6&"','"&pro7&"','"&pro8&"','"&pro6_name&"','"&pro7_name&"','"&ifbianhao&"',1,'"&siminfo&"')"
'取得添加商品ID,添加商品编号及推荐促销项目
set rs=server.createobject("ADODB.Recordset")
sql="select * from 56770_product order by id desc"
rs.open sql, conn, 1, 1
id=rs("id")
rs.close
set rs=nothing
if request("ifbianhao")="1" then
bianhao=bianhao1&id
else
bianhao=request("bianhao")
end if
conn.execute "update 56770_product set bianhao='"&bianhao&"' where id=" & id
'判断为何推荐
'if etj="on" then conn.execute "update 56770_product set etj=true where id=" & id
        if cx="on" then conn.execute "update 56770_product set cx=true where id=" & id
        if stj="on" then conn.execute "update 56770_product set stj=true where id=" & id
        if ytj="on" then conn.execute "update 56770_product set ytj=true where id=" & id
        conn.execute "update 56770_product set day=now() where id=" & id
        
        next
        response.write"<SCRIPT language=JavaScript>alert('商品添加成功 返回继续添加!');"
response.write"javascript:history.go(-2)</SCRIPT>"
response.end
end if
%>
2013-09-26 10:00
eournet
Rank: 2
等 级:论坛游民
帖 子:103
专家分:26
注 册:2010-5-22
收藏
得分:0 
你拿一段代码问别人对不对,你自己测试过没有,最起码有错误的话告诉位置
2013-09-26 19:51
huangjunyi
Rank: 2
等 级:论坛游民
帖 子:8
专家分:20
注 册:2013-9-25
收藏
得分:0 
回复 4楼 eournet
测试过。可以批量添加没问题。让高手看看是否有语法或者写法不对。是否有更好的方法。这是探讨而已。。
2013-09-28 11:07
快速回复:批量添加问题,貌似解决了,大家一起看下是否正确方法。
数据加载中...
 
   



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

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