asp下实现批量插入数据的方法
程序员文章站
2022-05-03 13:06:02
<% '申明变量 dim valname dim arrname dim objconn dim connstr if&nbs...
<%
'申明变量
dim valname
dim arrname
dim objconn
dim connstr
if request.form("mysubmit") = "确定" then
'数据库链接代码
set objconn=server.createobject("adodb.connection")
connstr = "provider=sqloledb;server=(local);database=test;uid=sa;pwd=123456;"
objconn.open connstr
'取得值
valname = cstr(request.form("myname"))
'插入数据库
arrname = split(valname,",")
arrpassword = split(valpassword,",")
'执行插入数据库的过程
for i = 0 to ubound(arrname)
'请自行更改sql语句
objconn.execute("insert into mytable(sname) values('"&trim(arrname(i))&"')")
next
response.write("数据插入成功")
'关闭数据库连接
objconn.close
set objconn = nothing
end if
%>
<html>
</head>
<body>
<input type="button" value="增加一条数据" onclick="addit()" />
<form method="post" action="test.asp" id="myform">
<div><input type="text" name="myname" /></div>
<input type="submit" value="确定" id="mysubmit" name="mysubmit" />
</form>
</body>
</html>
<script language="javascript" type="text/javascript">
function $(obj){
return document.getelementbyid(obj);
}
function addit(){
var myform = $("myform");
var mysubmit = $("mysubmit");
var mydiv = document.createelement("div");
var myinput = document.createelement("input");
myinput.setattribute("type","text");
myinput.setattribute("name","myname");
myform.insertbefore(mydiv,mysubmit);
mydiv.appendchild(myinput);
}
</script>
'申明变量
dim valname
dim arrname
dim objconn
dim connstr
if request.form("mysubmit") = "确定" then
'数据库链接代码
set objconn=server.createobject("adodb.connection")
connstr = "provider=sqloledb;server=(local);database=test;uid=sa;pwd=123456;"
objconn.open connstr
'取得值
valname = cstr(request.form("myname"))
'插入数据库
arrname = split(valname,",")
arrpassword = split(valpassword,",")
'执行插入数据库的过程
for i = 0 to ubound(arrname)
'请自行更改sql语句
objconn.execute("insert into mytable(sname) values('"&trim(arrname(i))&"')")
next
response.write("数据插入成功")
'关闭数据库连接
objconn.close
set objconn = nothing
end if
%>
<html>
</head>
<body>
<input type="button" value="增加一条数据" onclick="addit()" />
<form method="post" action="test.asp" id="myform">
<div><input type="text" name="myname" /></div>
<input type="submit" value="确定" id="mysubmit" name="mysubmit" />
</form>
</body>
</html>
<script language="javascript" type="text/javascript">
function $(obj){
return document.getelementbyid(obj);
}
function addit(){
var myform = $("myform");
var mysubmit = $("mysubmit");
var mydiv = document.createelement("div");
var myinput = document.createelement("input");
myinput.setattribute("type","text");
myinput.setattribute("name","myname");
myform.insertbefore(mydiv,mysubmit);
mydiv.appendchild(myinput);
}
</script>