Forums

ASP

This topic is locked

multiple insert using checkboxes (ASP/DW CS3)

Posted 10 Mar 2008 21:10:13
1
has voted
10 Mar 2008 21:10:13 paul mcmanus posted:
hey, i have a database where i have 2 tables, with one joining table.

tblENTRY - details of company with ENTRYID as PK
tblGENRES - listing of genres, with GENREID as PK
tblGENREGROUPS - joining table, with GENREGROUPID as PK, and ENTRYID and GENREID as other keys

i want it so when i choose multiple checkbox genres in a repeat region (taken from a recordset created by selecting * from tblGENRES) and it to insert the relevant rows with each one having the same ENTRYID, different GENREID (whatever is chosen).

I have done a lot of searching online and there only seems to be hints and tips on updating or deleting, or using ASP.net and other things, but I really need help!

I know I need to create a loop to get the array into separate lines, but i am really struggling...

here is some code i have but it blatently doesn't work:

<%
If (CStr(Request("MM_insert") = "form1" Then
If (Not MM_abortEdit) Then
' execute the insert

Dim arrValue, arrCount, i
arrValue=Split(Request.Form("genre", ","
arrCount=UBound(arrValue)
For i=0 To arrCount
Dim MM_editCmd
Set MM_editCmd = Server.CreateObject ("ADODB.Command"
MM_editCmd.ActiveConnection = MM_tugonline_STRING
MM_editCmd.CommandText = "INSERT INTO dbo.SubGenreGroups (SubGenreID, EntryID) VALUES ( " & arrValue(i) & ", " & EntryID & " )"
MM_editCmd.Prepared = true
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 5, 1, -1, MM_IIF(Request.Form("genre", 1, 0)) ' adDouble
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param2", 5, 1, -1, MM_IIF(Request.Form("EntryID", Request.Form("EntryID", null)) ' adDouble
MM_editCmd.Execute
Next
MM_editCmd.ActiveConnection.Close

' append the query string to the redirect URL
Dim MM_editRedirectUrl
MM_editRedirectUrl = "add_ap.asp"
If (Request.QueryString <> "" Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0) Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If
Response.Redirect(MM_editRedirectUrl)
End If
End If
%>

Reply to this topic