Allora, ho trovato spulciando nel forum un 3d di Baol che era proprio ciò che mi serviva...
Il codice funziona alla perfezione meno che per una cosa:
Per i campi di testo e le immagini fa il suo lavoro, ma nel momento in cui provo a passare un valore numerico di tipo "select" nei quali prendo dal database valore e id mi da questo errore:
Tipo di errore:
ADODB.Recordset (0x800A0CC1)
Impossibile trovare l'oggetto nell'insieme corrispondente al nome o al numero richiesto.
/solaut/public/Inserisci.asp, line 50
La riga in questione (credo si fermi al primo errore) è:
Rs("Marche") = oUpload.Form("Marche")
che sarebbe poi la prima che va a prendere il campo select. Nel Form funziona perchè mi da i valori che mi prendo dal database, non capisco perchè quando vado ad inviare il form mi da questo errore.
Ovviamente se metto sotto forma di commento il codice di tutti i campi "select" funziona alla grande, soltanto che senza quei valori è tutto inutile.
Grazie
codice:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%Response.charset="utf-8"%>
<%
Set rsMarche = Server.CreateObject("ADODB.RecordSet")
sql = "SELECT * FROM Marche ORDER By Marche Asc"
rsMarche.Open sql, Conn, 3, 3
%>
<%
Set rsAlimentazioni = Server.CreateObject("ADODB.RecordSet")
sql = "SELECT * FROM Alimentazioni ORDER By Alimentazioni Asc"
rsAlimentazioni.Open sql, Conn, 3, 3
%>
<%
Set rsCategorie = Server.CreateObject("ADODB.RecordSet")
sql = "SELECT * FROM Categorie ORDER By Categorie Asc"
rsCategorie.Open sql, Conn, 3, 3
%>
<%
Set rsStati = Server.CreateObject("ADODB.RecordSet")
sql = "SELECT * FROM Stati ORDER By Stati Asc"
rsStati.Open sql, Conn, 3, 3
%>
<%
If Request.QueryString("Save")="1" then
Dim oUpload
Set oUpload = new cUpload
oUpload.AutoRename = True
oUpload.Overwrite = False
oUpload.SetPath "files\" 'Impostazione del percorso
oUpload.Load
While Not oUpload.EOF
oUpload.Save()
Select Case lCase(oUpload.Files("InputName"))
Case "img"
FileName_img = oUpload.GetFileName()
Case "img1"
FileName_img1 = oUpload.GetFileName()
Case "img2"
FileName_img2 = oUpload.GetFileName()
End Select
oUpload.MoveNext
Wend
'Set Conn = Server.CreateObject("ADODB.Connection")
'Conn.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("../mdb-database/solaut.mdb")
Set Rs=server.CreateObject("ADODB.Recordset")
Rs.Open "Automobili",Conn,3,3
Rs.AddNew
Rs("Marche") = oUpload.Form("Marche")
Rs("Alimentazioni") = oUpload.Form("Alimentazioni")
Rs("Categorie") = oUpload.Form("Categorie")
Rs("Stati") = oUpload.Form("Stati")
Rs("Modello") = oUpload.Form("Modello")
Rs("Immatricolazione") = oUpload.Form("Immatricolazione")
Rs("Prezzo") = oUpload.Form("Prezzo")
Rs("Km") = oUpload.Form("Km")
Rs("Descrizione") = oUpload.Form("Descrizione")
Rs("img") = FileName_img
Rs("img1") = FileName_img1
Rs("img2") = FileName_img2
Rs.update
Rs.Close
Set Rs = Nothing
End if
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Soluzione Auto - Gestione</title>
<link href="../Gestione.css" rel="stylesheet" type="text/css">
</head>
<body>
<FORM ACTION="?save=1" METHOD="Post" enctype="multipart/form-data">
<table width="80%" border="1" align="center">
<tr>
<td colspan="2" align="center" class="big">Inserimento Automobili</td>
</tr>
<tr>
<td width="50%"></td>
<td width="50%"></td>
</tr>
<tr>
<td>Marca: </td>
<td><label>
<select name="Marche" id="Marche">
<%
Do Until rsMarche.EOF
%>
<%
Dim strIdMarche, strMarche
strIdMarche = rsMarche("IdMarche")
strMarche = rsMarche("Marche")
%>
<option value="<%=strIdMarche%>"><%=strMarche%></option>
<%
rsMarche.MoveNext
Loop
%>
</select>
</label></td>
</tr>
<tr>
<td>Alimentazione:</td>
<td><label>
<select name="Alimentazioni" id="Alimentazioni">
<%
Do Until rsAlimentazioni.EOF
%>
<%
Dim strIdAlimentazioni, strAlimentazioni
strIdAlimentazioni = rsAlimentazioni("IdAlimentazioni")
strAlimentazioni = rsAlimentazioni("Alimentazioni")
%>
<option value="<%=strIdAlimentazioni%>"><%=strAlimentazioni%></option>
<%
rsAlimentazioni.MoveNext
Loop
%>
</select>
</label></td>
</tr>
<tr>
<td>Categoria:</td>
<td><label>
<select name="Categorie" id="Categorie">
<%
Do Until rsCategorie.EOF
%>
<%
Dim strIdCategorie, strCategorie
strIdCategorie = rsCategorie("IdCategorie")
strCategorie = rsCategorie("Categorie")
%>
<option value="<%=strIdCategorie%>"><%=strCategorie%></option>
<%
rsCategorie.MoveNext
Loop
%>
</select>
</label></td>
</tr>
<tr>
<td>Stato:</td>
<td><label>
<select name="Stati" id="Stati">
<%
Do Until rsStati.EOF
%>
<%
Dim strIdStati, strStati
strIdStati = rsStati("IdStati")
strStati = rsStati("Stati")
%>
<option value="<%=strIdStati%>"><%=strStati%></option>
<%
rsStati.MoveNext
Loop
%>
</select>
</label></td>
</tr>
<tr>
<td>Modello:</td>
<td><label>
<input type="text" name="Modello" id="Modello">
</label></td>
</tr>
<tr>
<td>Immatricolazione:</td>
<td><label>
<input type="text" name="Immatricolazione" id="Immatricolazione">
</label></td>
</tr>
<tr>
<td>Prezzo:</td>
<td><label>
<input type="text" name="Prezzo" id="Prezzo">
</label></td>
</tr>
<tr>
<td>Chilometri:</td>
<td><label>
<input type="text" name="Km" id="Km">
</label></td>
</tr>
<tr>
<td>Descrizione:</td>
<td><label>
<textarea name="Descrizione" id="Descrizione" cols="45" rows="5"></textarea>
</label></td>
</tr>
<tr> </tr>
<tr>
<td>Immagine 1:</td>
<td><input type="file" name="img" /></td>
</tr>
<tr>
<td>Immagine 2:</td>
<td><input type="file" name="img1" /></td>
</tr>
<tr>
<td>Immagine 3:</td>
<td><input type="file" name="img2" /></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td colspan="2" align="center"><INPUT NAME="Enter" TYPE="Submit" value="Invia"></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td colspan="2" align="center">Torna alla gestione</td>
</tr>
</table>
</FORM>
</body>
</html>
<%
rsMarche.Close
Set rsMarche = Nothing
rsAlimentazioni.Close
Set rsAlimentazioni = Nothing
rsCategorie.Close
Set rsCategorie = Nothing
rsStati.Close
Set rsStati = Nothing
Conn.Close
Set Conn=Nothing
Set oUpload = Nothing
%>