Newsgroup: it.comp.www.asp
Titolo: Aggiungere Nuovo Record in un DB Access, come?

Premetto che sono completamente neofita della programmazione ASP.
Sto cercando di creare una pagina Internet che contenga in modo dinamico 
l'elenco di un database.
La visualizzazione della lista completa del DB funziona correttamente.
Nasce pero' un problema quando vado ad aggiungere un nuovo iscritto. Infatti 
mi si apre la pagina di inserimento dei dati di un nuovo iscritto ma appena 
clicco sul pulsante Salva (ovvero il submit) non mi si apre correttamente la 
pagina che chiama la AddItemAction() che è la Sub che salva.
Eppure non capisco cosa ci possa essere di sbagliato in questa sub:
Sub AddItemAction()
 MySQL="Select * from " & strTable
 Set MyRs=MyConn.Execute(MySQL)
 numerocampi=MyRs.fields.count -1
 for i=0 to numerocampi
  'if Not MyRs(i).name = "NUMERO_TESSERA" then
   str = MyRs(i).name
   if not i = numerocampi then
    str1 = str1 & "[" & str & "], "
   else
    str1 = str1 & "[" & str & "]"
   end if
   strNames = Request(str)
   if not i = numerocampi then
    sqlNames1 = sqlNames1 & "'" & strNames & "', "
   else
    sqlNames1 = sqlNames1 & "'" &  strNames & "'"
   end if
  'end if
 next
 MySQL1="Insert INTO " & strTable & " (" & str1 & ") VALUES (" & sqlNames1 & 
")"
 Set MyRs1=MyConn.Execute(MySQL1)
 MyConn.Close
 set MyConn=nothing
 Response.Redirect strFile
End Sub
Qualcuno di voi sa aiutarmi?
Grazie
Thommy
-------------------------------------CODICE 
COMPLETO----------------------------------------
<%
strFile = "GestioneCompletaAnagraficaIscritti.asp"    'il nome di questo 
file
strTable = "Rubrica"           'nome tabella
strKey = "NUMERO_TESSERA"          'chiave primaria, contatore
bgHeaderColor = "Orange"
fontHeaderColor = "black"
bgColor1 = "Silver"
fontColor1 = "Black"
bgColor2 = "White"
fontColor2 = "Black"
Set MyConn=Server.CreateObject("ADODB.Connection")
MyConn.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & 
server.MapPath("/mdb-database/Circolo_DB.mdb")
'**************************************
'azioni da eseguire
'**************************************
Select Case Request("mode")
 Case "AddItem"
  AddItem
 Case "AddItemAction"
  AddItemAction
 Case "EditItem"
  EditItem
 Case "EditItemAction"
  EditItemAction
 Case "DelItem"
  delItem
 Case Else
  ShowAll
End Select
'**************************************
'mostrare tutti i record
'FORTEMENTE SCONSIGLIATO PER I DATABASE DI GRANDE DIMENSIONE
'**************************************
Sub ShowAll()
 MySQL="Select * from " & strTable
 Set MyRs=MyConn.Execute(MySQL)
 Response.write ("<h2> Gestione Anagrafica Circolo della Liberta - Monza e 
Brianza</h2>")
 Response.write ("<p><a href=""" & strFile & "?mode=AddItem""><font 
size=""2"">AGGIUNGI NUOVO</font></a></p>")
 Response.write ("<table border=""1"" cellpadding=""4"" cellspacing=""1"">")
 Response.write ("<tr>")
 numerocampi=MyRs.fields.count -1
 Response.write ("<td bgcolor=""" & bgHeaderColor & """ align=""Center"" 
nowrap><font color=""" & fontHeaderColor & """ size=""2"">Elimina 
Iscritto</font></td>")
 Response.write ("<td bgcolor=""" & bgHeaderColor & """ align=""Center"" 
nowrap><font color=""" & fontHeaderColor & """ size=""2"">Modifica 
Iscritto</font></td>")
 for i=0 to numerocampi
  'if Not MyRs(i).name = "NUMERO_TESSERA" then
   Response.write ("<td bgcolor=""" & bgHeaderColor & """ align=""Center"" 
nowrap><font color=""" & fontHeaderColor & """ size=""2"">" & MyRs(i).name & 
"</font>&nbsp;</td>")
  'end if
 next
 Response.write ("</tr>")
 do while not MyRs.eof
 if bgColor = bgColor2 then
  bgColor = bgColor1
  fontColor = fontColor1
 else
  bgColor = bgColor2
  fontColor = fontColor2
 end if
 Response.write ("<tr>")
 Response.write ("<td align=""Center"" valign=""Top"" bgcolor=""" & bgColor 
& """>")
 Response.write ("<font color=""" & fontColor & """><A HREF=""" & strFile & 
"?mode=DelItem&which=" & MyRs(strKey) & """>Elimina</A></font></td>")
 Response.write ("<td align=""Center"" valign=""Top"" bgcolor=""" & bgColor 
& """>")
 Response.write ("<font color=""" & fontColor & """><A HREF=""" & strFile & 
"?mode=EditItem&which=" & MyRs(strKey) & """>Modifica</A></font></td>")
 for i = 0 to numerocampi
  'if Not MyRs(i).name = "NUMERO_TESSERA" then
   if MyRs(i).name = "PRICE" then
    ThisRecord = FormatCurrency(MyRs(i))
    strAlign = "right"
   else
    ThisRecord = MyRs(i)
    strAlign = ""
   end if
   If IsNull(ThisRecord) or ThisRecord = "" Then
    ThisRecord = "&nbsp;"
   end if
   ThisRecord  = Replace(ThisRecord,vbCrLf,"<BR>")
   Response.write ("<td align=""" & strAlign & """ valign=top bgcolor=""" & 
bgColor & """><font color=""" & fontColor & """>" & Thisrecord & 
"</font>&nbsp;</td>")
  'end if
 next
 Response.write ("</tr>")
 MyRs.movenext
 loop
 Response.write ("</table>")
 MyRs.close
 Set MyRs= Nothing
end sub
'**************************************
'aggiungi
'**************************************
Sub AddItem()
 MySQL="Select * from " & strTable
 Set MyRs=MyConn.Execute(MySQL)
 Response.write ("<h2>Aggiungi nuovo Record a " & strTable & "</h2>")
 Response.write ("<form action=""" & strFile & "?mode=AddItemAction"" 
method=""post"" NUMERO_TESSERA=form1 name=form1>")
 Response.write ("<table>")
 numerocampi=MyRs.fields.count -1
 for i=0 to numerocampi
 if Not MyRs(i).name = "NUMERO_TESSERA" then
  ThisRecord = MyRs(i)
  ThisRecordName = MyRs(i).name
  If IsNull(ThisRecord) or ThisRecord = "" Then
   ThisRecord = "&nbsp;"
  end if
 Response.write ("<tr>")
 Response.write ("<td align=""right"">" & ThisRecordName & ": </td>")
 Response.write ("<td> <input name=""" & ThisRecordName & """ 
type=""text""></td>")
 Response.write ("</tr>")
 end if
 next
 Response.write ("<tr>")
 Response.write ("<td align=""right""><input name=""Salva"" type=submit 
value=""Salva""></td>")
 Response.write ("<td><input name=""Resetta Campi"" type=reset 
value=""Resetta Campi""></td>")
 Response.write ("</tr>")
 Response.write ("</table>")
 Response.write ("</form>")
 Response.write ("<a href=""" & strFile & """>Esci dall'aggiunta di un nuovo 
Iscritto</a>")
End Sub
Sub AddItemAction()
 MySQL="Select * from " & strTable
 Set MyRs=MyConn.Execute(MySQL)
 numerocampi=MyRs.fields.count -1
 for i=0 to numerocampi
  'if Not MyRs(i).name = "NUMERO_TESSERA" then
   str = MyRs(i).name
   if not i = numerocampi then
    str1 = str1 & "[" & str & "], "
   else
    str1 = str1 & "[" & str & "]"
   end if
   strNames = Request(str)
   if not i = numerocampi then
    sqlNames1 = sqlNames1 & "'" & strNames & "', "
   else
    sqlNames1 = sqlNames1 & "'" &  strNames & "'"
   end if
  'end if
 next
 MySQL1="Insert INTO " & strTable & " (" & str1 & ") VALUES (" & sqlNames1 & 
")"
 Set MyRs1=MyConn.Execute(MySQL1)
 MyConn.Close
 set MyConn=nothing
 Response.Redirect strFile
End Sub
'**************************************
'modificare
'**************************************
Sub EditItem()
 Response.write ("<h2>Modifica record nella tabella " & strTable & "</h2>")
 which=request("which")
 if isNumeric(which) then
  MySQL="SELECT * FROM " & strTable & " Where " & strKey & " = " & which
 else
  MySQL="SELECT * FROM " & strTable & " Where " & strKey & " = '" & which & 
"'"
 end if
 Set MyRs=MyConn.Execute(MySQL)
 Response.write ("<FORM ACTION=""" & strFile & "?mode=EditItemAction"" 
METHOD=POST>")
 Response.write ("<input name=""NUMERO_TESSERA"" type=""hidden"" value=""" & 
MyRs(strKey) & """>")
 Response.write ("<table>")
 numerocampi=MyRs.fields.count -1
 for i=0 to numerocampi
 if Not MyRs(i).name = "NUMERO_TESSERA" then
  ThisRecord = MyRs(i)
  ThisRecordName = MyRs(i).name
  If IsNull(ThisRecord) or ThisRecord = "" Then
   ThisRecord = "&nbsp;"
  end if
 Response.write ("<tr>")
 Response.write ("<td align=""right"">" & ThisRecordName & ": </td>")
 Response.write ("<td> <input name=""" & ThisRecordName & """ type=""text"" 
value=""" & MyRs(i) & """></td>")
 Response.write ("</tr>")
 end if
 next
 Response.write ("<tr>")
 Response.write ("<td align=""right""><INPUT NAME=""Aggiorna"" TYPE=Submit 
Value=""Aggiorna""></td>")
 Response.write ("<td><INPUT NAME=""Resetta campi"" TYPE=reset 
Value=""Resetta campi""></td>")
 Response.write ("</tr>")
 Response.write ("</table>")
 Response.write ("</FORM>")
 Response.write ("<a href=""" & strFile & """>Esci dalla modifica di un 
nuovo Iscritto</a>")
 MyRs.close
 Set MyRs= Nothing
End Sub
Sub EditItemAction()
 which = Request(strKey)
 if isNumeric(which) then
  MySQL="SELECT * FROM " & strTable & " Where " & strKey & " = " & which
 else
  MySQL="SELECT * FROM " & strTable & " Where " & strKey & " = '" & which & 
"'"
 end if
 'MySQL="Select * from " & strTable
 Set MyRs=MyConn.Execute(MySQL)
 numerocampi=MyRs.fields.count -1
 for i=0 to numerocampi
  'if Not MyRs(i).name = "NUMERO_TESSERA" then
   str = MyRs(i).name
   strNames = Request(str)
   if not i = numerocampi then
    str1 = str1 & "[" & str & "] = '" & strNames & "', "
   else
    str1 = str1 & "[" & str & "] = '" & strNames & "'"
   end if
  'end if
 next
 if isNumeric(which) then
  MySQL1="UPDATE " & strTable & " SET " & str1 & " Where " & strKey & " = " 
& which
 else
  MySQL1="UPDATE " & strTable & " SET " & str1 & " Where " & strKey & " = '" 
& which & "'"
 end if
 'MySQL1="UPDATE " & strTable & " SET " & str1 & " Where NUMERO_TESSERA=" & 
which
 Set MyRs1=MyConn.Execute(MySQL1)
 MyConn.Close
 set MyConn=nothing
 Response.Redirect strFile
End Sub
'**************************************
'elimina record
'**************************************
Sub DelItem()
 which=request("which")
 if isNumeric(which) then
  MySQL="delete * from " & strTable & " Where " & strKey & " = " & which
 else
  MySQL="delete * from " & strTable & " Where " & strKey & " = '" & which & 
"'"
 end if
 Set MyRs=MyConn.Execute(MySQL)
 MyConn.Close
 set MyConn=nothing
 Response.Redirect strFile
End Sub
%>

 Set MyRs1=MyConn.Execute(MySQL1)
..............
Cosě hai i campi e i valori, come va?

 Set MyRs1=MyConn.Execute(MySQL1)
