经典ASP向数据库添加多行

时间:2017-02-06 16:44:01

标签: asp-classic

您好我正在使用以下代码将数据添加到数据库中,我需要能够同时向数据库中添加几行。这些行将插入到同一个DB中但具有不同的值。请参阅下面的代码;

    <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="../Connections/Conn02.asp" -->
<%
Dim MM_editAction
MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
If (Request.QueryString <> "") Then
  MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString)
End If

' boolean to abort record edit
Dim MM_abortEdit
MM_abortEdit = false
%>
<%
If (CStr(Request("MM_insert")) = "form1") Then
  If (Not MM_abortEdit) Then
    ' execute the insert
    Dim MM_editCmd

    Set MM_editCmd = Server.CreateObject ("ADODB.Command")
    MM_editCmd.ActiveConnection = MM_Conn02_STRING
    MM_editCmd.CommandText = "INSERT INTO mydatabase.test (name) VALUES (?)" 
    MM_editCmd.Prepared = true
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 201, 1, -1, Request.Form("namex")) ' adLongVarChar
    MM_editCmd.Execute
    MM_editCmd.ActiveConnection.Close
  End If
End If
%>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>

<form ACTION="<%=MM_editAction%>" METHOD="POST" name="form1">
<input type="text" name="namex">
<input type="submit">
<input type="hidden" name="MM_insert" value="form1">
</form>


</body>
</html>

我可以通过用户可能为字段名称输入多个值的表单进行此循环吗?

这只是我试图解决的一个例子。

1 个答案:

答案 0 :(得分:-1)

当然你可以这样做。为此,你应该搜索经典的asp动态表格&#34;话题

愿这个链接可以帮到你。如果我是你的鞋子,我更愿意学习Asp.Net。经典Asp到老:(。我在2011年左右停止工作。

Variable Number of Input Fields in Classic-ASP form

https://bytes.com/topic/asp-classic/answers/701049-dynamic-variable-array-asp-form-text-input