Stefan Motz
asked on
SQL Syntax - Insert multiple records with one submission - Classic ASP
Hi Experts,
My query returns multiple records that I would like to submit to a different table with a single submission.
I'm using checkboxes for each record that I would like to insert into my new table.
My "Process.asp" can insert only one record at once. How can I modify it to submit all records at once. Please take a look at my code.
I would really appreciate your help.
And this is my "Process.asp" that needs to be modified in order to insert multiple records:
My query returns multiple records that I would like to submit to a different table with a single submission.
I'm using checkboxes for each record that I would like to insert into my new table.
My "Process.asp" can insert only one record at once. How can I modify it to submit all records at once. Please take a look at my code.
I would really appreciate your help.
<html>
<head>
<title></title>
<link rel="stylesheet" href="/RouteMapper/css/Styles.css" type="text/css" />
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function checkLikeMe($) {
var x = document.getElementsByName('DeviceName');
for (var y = 0; y < x.length; y++)
x[y].checked = $;
}
// End -->
</script>
</head>
<body>
<form name="contact_form" method="post" action="Process.asp">
<table border="1">
<tr>
<th><input type="checkbox" onClick="checkLikeMe(this.checked)"></th>
<th>Device Name</th>
<th>OU</th>
<th>SubOU</th>
</tr>
<%
rs.AbsolutePage = intPage
For intRecord = 1 To rs.PageSize
%>
<tr>
<td><input type="checkbox" name="DeviceName" value="<%=rs("DeviceName") %>"></td>
<td><%=rs("DeviceName")%></td>
<td><%=rs("OU")%></td>
<td><%=rs("SubOU")%></td>
</tr>
<%
rs.MoveNext
If rs.EOF Then Exit For
Next
rs.Close
set rs = Nothing
AdoCon.Close
set AdoCon = nothing
%>
</table>
<center>
<br />
<select name="Environment">
<option value="5">Dev</option>
<option value="4">Stage</option>
</select>
<input type="Submit" name="Submit" value="Submit" />
</center>
</form>
</center>
</body>
</html>
And this is my "Process.asp" that needs to be modified in order to insert multiple records:
<!-- #include virtual="/RouteMapper/Connections/APSConn.asp" -->
<%
'declare variables
Dim AdoCon, strSQL, strDeviceName, strOU, strSubOU, Environment
'Set values into variables
strDeviceName = request.Form("DeviceName")
strOU = request.Form("OU")
strSubOU = request.Form("SubOU")
strEnvironment = request.Form("Environment")
'create SQL string for inserting data into database
strSQL = "INSERT INTO TestTable (DeviceName, OU, SubOU, Environment) VALUES ('"& strDeviceName &"','"& strOU &"','"& strSubOU &"','"& strEnvironment &"')"
'now add data with Execute() method
AdoCon.Execute(strSql)
'close AdoConection object
AdoCon.Close
Set AdoCon = Nothing
'Redirect to the completed.asp page
Response.Redirect "Default.asp"
%>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I don't know if there's a single best way, but options include:
Whichever method you choose, you have to combine them all together in the form side, and set that as the value of the checkbox input. Then, as you harvest it, you'll have to do the reverse, and split the values apart again.
- Concatenating them together, using a unique delimiter that you know doesn't show up in the data (such as a comma, colon, or pipe symbol)
- Making a JSON object
Whichever method you choose, you have to combine them all together in the form side, and set that as the value of the checkbox input. Then, as you harvest it, you'll have to do the reverse, and split the values apart again.
ASKER
I get an error after I submit. Would you know the reason?
Microsoft VBScript compilation error '800a0401'
Expected end of statement
/ewr/lab/Process.asp, line 5
strDeviceName = request.Form("DeviceName") [index]
-------------------------- ---------- ------^
Microsoft VBScript compilation error '800a0401'
Expected end of statement
/ewr/lab/Process.asp, line 5
strDeviceName = request.Form("DeviceName")
--------------------------
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you, now it inserts the checked records. Unfortunately it doesn't insert "Environment". It just sends the value 0, not the one selected in the dropdown. What can be the reason?
ASKER
The problem is fixed, thank you so much for your help!
ASKER
Thank you very much, it's working the way I wanted it. I'm really grateful for your help.
ASKER
What would be the best way to also harvest OU and SubOU?