Salve a tutti,
In un file di gestione.asp di Categorie e sottocategorie che si compongono all'interno di un data-base access, all'interno del quale le due tabelle sono correlate ( IDcat <--> IDsotCat )
Devo impedire la duplicazione delle Categorie e sottocategorie che vado ad inserire.
Mi aiutate? Ecco lo script:
<%
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
%>
<%
' IIf implementation
Function MM_IIf(condition, ifTrue, ifFalse)
If condition = "" Then
MM_IIf = ifFalse
Else
MM_IIf = ifTrue
End If
End Function
%>
<%
If (CStr(Request("MM_insert")) = "cat") and request.Form("categoria") <> "" Then
If (Not MM_abortEdit) Then
' execute the insert
Dim MM_editCmd
Set MM_editCmd = Server.CreateObject ("ADODB.Command")
MM_editCmd.ActiveConnection = MM_inserisci_STRING
MM_editCmd.CommandText = "INSERT INTO Categorie (NomeCat) VALUES (?)"
MM_editCmd.Prepared = true
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 202, 1, 50, Request.Form("categoria")) ' adVarWChar
MM_editCmd.Execute
mex="Inserimento avvenuto con successo."
MM_editCmd.ActiveConnection.Close
End If
End If
%>
<%
If (CStr(Request("MM_insert")) = "sotcat") and Request.Form("sottocateg") <> "" Then
If (Not MM_abortEdit) Then
' execute the insert
Set MM_editCmd = Server.CreateObject ("ADODB.Command")
MM_editCmd.ActiveConnection = MM_inserisci_STRING
MM_editCmd.CommandText = "INSERT INTO Sottocategorie (NomeSottCat, IDCat) VALUES (?, ?)"
MM_editCmd.Prepared = true
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 202, 1, 50, Request.Form("sottocateg")) ' adVarWChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param2", 5, 1, -1, MM_IIF(Request.Form("categoria"), Request.Form("categoria"), null)) ' adDouble
MM_editCmd.Execute
mex="Inserimento avvenuto con successo."
MM_editCmd.ActiveConnection.Close
End If
End If
%>
<%
Dim categorie
Dim categorie_cmd
Dim categorie_numRows
Set categorie_cmd = Server.CreateObject ("ADODB.Command")
categorie_cmd.ActiveConnection = MM_inserisci_STRING
categorie_cmd.CommandText = "SELECT * FROM Categorie order by nomecat ASC"
categorie_cmd.Prepared = true
Set categorie = categorie_cmd.Execute
categorie_numRows = 0
%>

Rispondi quotando
