Ciao a tutti!
Sto creando un sito in ASP con Dreamweaver e non riesco a far aggiornare un record, perchè uno dei campi della tabella Prodotto_dett (cioè id_prodotto) è un contatore, anche se questo campo non lo modifico.
Un altro problema è che non mi fa fare le query con 2 o più parametri.
Io ho una pagina di ricerca dove è possibile inserire nome_prod e/o id_prodotto per cercare nel DB, ma 2 parametri non gli piacciono e mi dà il seguente errore:
Microsoft OLE DB Provider for ODBC Drivers error '80040e07'
[Microsoft][Driver ODBC Microsoft Access] Tipi di dati non corrispondenti nell'espressione criterio.
/ferramenta3d/ennesima3.asp, riga 62
Se faccio la ricerca inserendo un solo parametro nella WHERE della query, mi trova il record cercato, ma non me lo aggiorna e mi dà questo errore:
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[Microsoft][Driver ODBC Microsoft Access] Impossibile aggiornare "id_prodotto". Campo non aggiornabile.
/ferramenta3d/ennesima3.asp, riga 43
Vi metto di seguito il codice della pagina "ennesima3.asp":
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
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_update")) = "form1") Then
If (Not MM_abortEdit) Then
' execute the update
Dim MM_editCmd
Set MM_editCmd = Server.CreateObject ("ADODB.Command")
MM_editCmd.ActiveConnection = MM_Database3D_STRING
MM_editCmd.CommandText = "UPDATE Prodotto_dett SET articolo_cat = ?, id_prodotto = ?, marca = ?, nome_prod = ?, descrizione = ?, prezzo = ?, quantita = ?, foto = ? WHERE id_prodotto = ?"
MM_editCmd.Prepared = true
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 202, 1, 255, Request.Form("articolo_cat")) ' adVarWChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param2", 5, 1, -1, MM_IIF(Request.Form("id_prodotto"), Request.Form("id_prodotto"), null)) ' adDouble
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param3", 202, 1, 255, Request.Form("marca")) ' adVarWChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param4", 202, 1, 50, Request.Form("nome_prod")) ' adVarWChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param5", 202, 1, 50, Request.Form("descrizione")) ' adVarWChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param6", 5, 1, -1, MM_IIF(Request.Form("prezzo"), Request.Form("prezzo"), null)) ' adDouble
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param7", 5, 1, -1, MM_IIF(Request.Form("quantita"), Request.Form("quantita"), null)) ' adDouble
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param8", 203, 1, 1073741823, Request.Form("foto")) ' adLongVarWChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param9", 200, 1, 255, Request.Form("MM_recordId")) ' adVarChar
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close
End If
End If
%>
<%
Dim Recordset1
Dim Recordset1_cmd
Dim Recordset1_numRows
Dim a
Dim b
Set Recordset1_cmd = Server.CreateObject ("ADODB.Command")
Recordset1_cmd.ActiveConnection = MM_Database3D_STRING
a=Request.Form("id_prodotto")
b=Request.Form("nome_prod")
Recordset1_cmd.CommandText = "SELECT * FROM Prodotto_dett WHERE nome_prod='"& b &"' OR id_prodotto='"& a &"' "
Recordset1_cmd.Prepared = true
Set Recordset1 = Recordset1_cmd.Execute
Recordset1_numRows = 0
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento senza titolo</title>
</head>
<body>
<form action="<%=MM_editAction%>" method="post" name="form1" id="form1">
<table align="center">
<tr valign="baseline">
<td nowrap="nowrap" align="right">Articolo_cat:</td>
<td><input type="text" name="articolo_cat" value="<%=(Recordset1.Fields.Item("articolo_cat"). Value)%>" size="32" />
</td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Id_prodotto:</td>
<td><input type="text" name="id_prodotto" value="<%=(Recordset1.Fields.Item("id_prodotto").V alue)%>" size="32" />
</td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Marca:</td>
<td><input type="text" name="marca" value="<%=(Recordset1.Fields.Item("marca").Value)% >" size="32" />
</td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Nome_prod:</td>
<td><input type="text" name="nome_prod" value="<%=(Recordset1.Fields.Item("nome_prod").Val ue)%>" size="32" />
</td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Descrizione:</td>
<td><input type="text" name="descrizione" value="<%=(Recordset1.Fields.Item("descrizione").V alue)%>" size="32" />
</td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Prezzo:</td>
<td><input type="text" name="prezzo" value="<%=(Recordset1.Fields.Item("prezzo").Value) %>" size="32" />
</td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Quantita:</td>
<td><input type="text" name="quantita" value="<%=(Recordset1.Fields.Item("quantita").Valu e)%>" size="32" />
</td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Foto:</td>
<td><input type="text" name="foto" value="<%=(Recordset1.Fields.Item("foto").Value)%> " size="32" />
</td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"></td>
<td><input type="submit" value="Aggiorna record" />
</td>
</tr>
</table>
<input type="hidden" name="MM_update" value="form1" />
<input type="hidden" name="MM_recordId" value="<%= Recordset1.Fields.Item("articolo_cat").Value %>" />
</form>
</p>
</body>
</html>
<%
Recordset1.Close()
Set Recordset1 = Nothing
%>
Grazie mille!!!!

Rispondi quotando