Link to home
Start Free TrialLog in
Avatar of Stefan Motz
Stefan MotzFlag for United States of America

asked on

SQL Syntax - Insert multiple records and all fields with one submission - Classic ASP

Hi Experts,
I would like to insert all fields from my Form page. Right now I can submit only DeviceName and DestQueueId.
I would also like to submit the OU and SubOU fields but I don't know how to do it.
Please take a look at my Form and Process.asp pages
I would appreciate your help.

<html>
<head>
<title></title>
<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>
<br />
<select name="DestQueueId">
<option value="5">Dev</option>
<option value="4">Stage</option>
</select>
<input type="Submit" name="Submit" value="Submit" />
</form>

</body>
</html>

Open in new window

     
And this is the code of the Process.asp
<!-- #include virtual="/RouteMapper/Connections/APSConn.asp" -->
<%
for index = 1 to Request.Form("DeviceName").Count
   strDeviceName = Request.Form("DeviceName")(index)
   strDestQueueId = Request.Form("DestQueueId")

   'create SQL string for inserting data into database
   strSQL = "INSERT INTO TestTable (DeviceName, OU, SubOU, DestQueueId) VALUES ('"& strDeviceName &"','"& strOU &"','"& strSubOU &"','"& strDestQueueId &"')"

   'now add data with Execute() method
   AdoCon.Execute(strSql)
next

'close Connection object
AdoCon.Close
Set AdoCon = Nothing

'Redirect to the completed.asp page
Response.Redirect "Default.asp"
%>

Open in new window

Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

>> I would also like to submit the OU and SubOU fields but I don't know how to do it.

most likely you can create hidden fields for these 2 values so that when the page is posted, you can get its posted values.
ASKER CERTIFIED SOLUTION
Avatar of Jan Louwerens
Jan Louwerens
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Stefan Motz

ASKER

Thank you so much, I've learned a lot.
Thank you for the link, useful stuff.