Forums
This topic is locked
Multiple inserts into one table
Posted 05 Aug 2002 18:01:59
1
has voted
05 Aug 2002 18:01:59 Sharon Burkey posted:
I'm trying to submit several records using a dynamicmultiple select menu. Basically one member of staff (txtindID) can be associated with several projects (sel_project):<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="Connections/rjntest.asp" -->
<%
' *** Edit Operations: declare variables
MM_editAction = CStr(Request("URL")
If (Request.QueryString <> "" Then
MM_editAction = MM_editAction & "?" & Request.QueryString
End If
' boolean to abort record edit
MM_abortEdit = false
' query string to execute
MM_editQuery = ""
%>
<%
' *** Insert Record: set variables
If (CStr(Request("MM_insert") <> "" Then
MM_editConnection = MM_rjntest_STRING
MM_editTable = "tbl_projectlist"
MM_editRedirectUrl = "default.asp"
MM_fieldsStr = "sel_project|value|txtindID|value"
MM_columnsStr = "listproject|none,none,NULL|listind|none,none,NULL"
' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "|"
MM_columns = Split(MM_columnsStr, "|"
' set the form values
For i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(i+1) = CStr(Request.Form(MM_fields(i)))
Next
' append the query string to the redirect URL
If (MM_editRedirectUrl <> "" And Request.QueryString <> "" Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "" Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If
End If
%>
<%
' *** Insert Record: construct a sql insert statement and execute it
If (CStr(Request("MM_insert") <> "" Then
' create the sql insert statement
MM_tableValues = ""
MM_dbValues = ""
For i = LBound(MM_fields) To UBound(MM_fields) Step 2
FormVal = MM_fields(i+1)
MM_typeArray = Split(MM_columns(i+1),","
Delim = MM_typeArray(0)
If (Delim = "none" Then Delim = ""
AltVal = MM_typeArray(1)
If (AltVal = "none" Then AltVal = ""
EmptyVal = MM_typeArray(2)
If (EmptyVal = "none" Then EmptyVal = ""
If (FormVal = "" Then
FormVal = EmptyVal
Else
If (AltVal <> "" Then
FormVal = AltVal
ElseIf (Delim = "'" Then ' escape quotes
FormVal = "'" & Replace(FormVal,"'","''" & "'"
Else
FormVal = Delim + FormVal + Delim
End If
End If
If (i <> LBound(MM_fields)) Then
MM_tableValues = MM_tableValues & ","
MM_dbValues = MM_dbValues & ","
End if
MM_tableValues = MM_tableValues & MM_columns(i)
MM_dbValues = MM_dbValues & FormVal
Next
MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & " values (" & MM_dbValues & ""
If (Not MM_abortEdit) Then
' execute the insert
Set MM_editCmd = Server.CreateObject("ADODB.Command"
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close
If (MM_editRedirectUrl <> "" Then
Response.Redirect(MM_editRedirectUrl)
End If
End If
End If
%>
<%
set rs_projects = Server.CreateObject("ADODB.Recordset"
rs_projects.ActiveConnection = MM_rjntest_STRING
rs_projects.Source = "SELECT * FROM tbl_project ORDER BY ProjectName ASC"
rs_projects.CursorType = 0
rs_projects.CursorLocation = 2
rs_projects.LockType = 3
rs_projects.Open()
rs_projects_numRows = 0
%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
//-->
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<form METHOD="POST" name=frmdirectoryinitial action=
<%=MM_editAction%>>
<p> </p>
<p> </p>
<table cellspacing=4 cellpadding=0 width="50%" align=center border=0>
<tbody>
<tr valign=top>
<td>
<p align=left><b>Please indicate</b> <b>areas you are involved in:</b>
<div align=left>
<p> </p>
</div>
</td>
</tr>
</tbody>
</table>
<table cellspacing=4 cellpadding=0 width="50%" align=center border=0>
<tbody>
<tr valign=top>
<td valign=top height=19 width="150"><b>Projects</b></td>
<td valign=bottom height=19 colspan="2">
<select name="sel_project" size="5" multiple>
<%
While (NOT rs_projects.EOF)
%>
<option value="<%=(rs_projects.Fields.Item("ProjectID".Value)%>" ><%=(rs_projects.Fields.Item("ProjectName".Value)%></option>
<%
rs_projects.MoveNext()
Wend
If (rs_projects.CursorType > 0) Then
rs_projects.MoveFirst
Else
rs_projects.Requery
End If
%>
</select>
</td>
</tr>
<tr valign=top>
<td valign=bottom height=19 width="150"> </td>
<td valign=bottom height=19 colspan="2" onClick="MM_openBrWindow('addproject.asp','AddProject','toolbar=yes,location=yes,menubar=yes,scrollbars=yes,width=200,height=200')">Add
Project
<input type="checkbox" name="checkbox" value="checkbox" onClick="MM_openBrWindow('addproject.asp','AddProject','width=400,height=200')">
</td>
</tr>
<tr valign=top>
<td valign=bottom height=19 width="150"> </td>
<td valign=bottom height=19 colspan="2">
<input type="text" name="txtindID" value="1">
</td>
</tr>
<tr valign=top>
<td valign=bottom height=19 width="150"> </td>
<td valign=bottom height=19 colspan="2">
<input type="submit" name="Submit" value="Submit">
</td>
</tr>
</tbody>
</table>
<p> </p>
<p>
<input type="hidden" name="MM_insert" value="true">
</form>
</body>
</html>
<%
rs_projects.Close()
%>