ASP实现批量插入数据
ASP #批量2012-05-09 10:22
<%
'申明变量
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>
相关文章
- ASP网站生成静态html页 2012/05/09
- ASP正则替换空格和回车符函数 2012/05/09
- FSO文件处理函数详解 2012/05/09
- asp中Byval/Byref区别 2012/05/09
- ASP遍历XML的例子 2012/05/09
- ASP的ubb函数 2012/05/08
- ASP正则提取href标签的值函数 2012/05/08
- ASP电话号码正则表达式函数 2012/05/08
- ASP四个电子邮箱验证函数 2012/05/08
- ASP正则表达式过滤html函数 2012/05/08