codice:
' Add record
Function AddRow()
On Error Resume Next
Dim rs, sSql, sFilter
Dim rsnew
Dim bCheckKey, sSqlChk, sWhereChk, rsChk
Dim bInsertRow
' Check for duplicate key
bCheckKey = True
sFilter = annunci.SqlKeyFilter
If annunci.idappartamenti.CurrentValue = "" Or IsNull(annunci.idappartamenti.CurrentValue) Then
bCheckKey = False
Else
sFilter = Replace(sFilter, "@idappartamenti@", ew_AdjustSql(annunci.idappartamenti.CurrentValue)) ' Replace key value
End If
If Not IsNumeric(annunci.idappartamenti.CurrentValue) Then
bCheckKey = False
End If
If bCheckKey Then
Set rsChk = annunci.LoadRs(sFilter)
If Not (rsChk Is Nothing) Then
Session(EW_SESSION_MESSAGE) = "Duplicate value for primary key"
rsChk.Close
Set rsChk = Nothing
AddRow = False
Exit Function
End If
End If
' Add new record
sFilter = "(0 = 1)"
annunci.CurrentFilter = sFilter
sSql = annunci.SQL
Set rs = Server.CreateObject("ADODB.Recordset")
rs.CursorLocation = EW_CURSORLOCATION
rs.Open sSql, conn, 1, 2
rs.AddNew
If Err.Number <> 0 Then
Session(EW_SESSION_MESSAGE) = Err.Description
rs.Close
Set rs = Nothing
AddRow = False
Exit Function
End If
' Field categoria
Call annunci.categoria.SetDbValue(annunci.categoria.CurrentValue, Null)
rs("categoria") = annunci.categoria.DbValue
' Field contatto
Call annunci.contatto.SetDbValue(annunci.contatto.CurrentValue, Null)
rs("contatto") = annunci.contatto.DbValue
' Field email
Call annunci.email.SetDbValue(annunci.email.CurrentValue, Null)
rs("email") = annunci.email.DbValue
' Field telefono
Call annunci.telefono.SetDbValue(annunci.telefono.CurrentValue, Null)
rs("telefono") = annunci.telefono.DbValue
' Field cellulare
Call annunci.cellulare.SetDbValue(annunci.cellulare.CurrentValue, Null)
rs("cellulare") = annunci.cellulare.DbValue
' Field idregione
Call annunci.idregione.SetDbValue(annunci.idregione.CurrentValue, Null)
rs("idregione") = annunci.idregione.DbValue
' Field idprovincia
Call annunci.idprovincia.SetDbValue(annunci.idprovincia.CurrentValue, Null)
rs("idprovincia") = annunci.idprovincia.DbValue
' Field idcomune
Call annunci.idcomune.SetDbValue(annunci.idcomune.CurrentValue, Null)
rs("idcomune") = annunci.idcomune.DbValue
' Field localita
Call annunci.localita.SetDbValue(annunci.localita.CurrentValue, Null)
rs("localita") = annunci.localita.DbValue
' Field indirizzo
Call annunci.indirizzo.SetDbValue(annunci.indirizzo.CurrentValue, Null)
rs("indirizzo") = annunci.indirizzo.DbValue
' Field cameredaletto
Call annunci.cameredaletto.SetDbValue(annunci.cameredaletto.CurrentValue, Null)
rs("cameredaletto") = annunci.cameredaletto.DbValue
' Field bagni
Call annunci.bagni.SetDbValue(annunci.bagni.CurrentValue, Null)
rs("bagni") = annunci.bagni.DbValue
' Field metriquadrati
Call annunci.metriquadrati.SetDbValue(annunci.metriquadrati.CurrentValue, Null)
rs("metriquadrati") = annunci.metriquadrati.DbValue
' Field postoauto
Call annunci.postoauto.SetDbValue(annunci.postoauto.CurrentValue, Null)
rs("postoauto") = annunci.postoauto.DbValue
' Field garage
Call annunci.garage.SetDbValue(annunci.garage.CurrentValue, Null)
rs("garage") = annunci.garage.DbValue
' Field giardino
Call annunci.giardino.SetDbValue(annunci.giardino.CurrentValue, Null)
rs("giardino") = annunci.giardino.DbValue
' Field piscina
Call annunci.piscina.SetDbValue(annunci.piscina.CurrentValue, Null)
rs("piscina") = annunci.piscina.DbValue
' Field ascensore
Call annunci.ascensore.SetDbValue(annunci.ascensore.CurrentValue, Null)
rs("ascensore") = annunci.ascensore.DbValue
' Field piano
Call annunci.piano.SetDbValue(annunci.piano.CurrentValue, Null)
rs("piano") = annunci.piano.DbValue
' Field tot_piani
Call annunci.tot_piani.SetDbValue(annunci.tot_piani.CurrentValue, Null)
rs("tot_piani") = annunci.tot_piani.DbValue
' Field veranda
Call annunci.veranda.SetDbValue(annunci.veranda.CurrentValue, Null)
rs("veranda") = annunci.veranda.DbValue
' Field descrizione
Call annunci.descrizione.SetDbValue(annunci.descrizione.CurrentValue, Null)
rs("descrizione") = annunci.descrizione.DbValue
' Field IP
annunci.IP.DbValue = ew_CurrentUserIP
rs("IP") = annunci.IP.DbValue
' Field data
annunci.data.DbValue = ew_CurrentDate
rs("data") = annunci.data.DbValue
' Field foto1
Call annunci.foto1.Upload.SaveToSession() ' Save file value to Session
annunci.foto1.Upload.DbValue = rs("foto1") ' Get original value
If IsNull(annunci.foto1.Upload.Value) Then
rs("foto1") = Null
Else
rs("foto1") = ew_UploadFileNameEx(ew_UploadPathEx(True, "public/"), annunci.foto1.Upload.FileName)
End If
' Field foto2
Call annunci.foto2.Upload.SaveToSession() ' Save file value to Session
annunci.foto2.Upload.DbValue = rs("foto2") ' Get original value
If IsNull(annunci.foto2.Upload.Value) Then
rs("foto2") = Null
Else
rs("foto2") = ew_UploadFileNameEx(ew_UploadPathEx(True, "public/"), annunci.foto2.Upload.FileName)
End If
' Field foto3
Call annunci.foto3.Upload.SaveToSession() ' Save file value to Session
annunci.foto3.Upload.DbValue = rs("foto3") ' Get original value
If IsNull(annunci.foto3.Upload.Value) Then
rs("foto3") = Null
Else
rs("foto3") = ew_UploadFileNameEx(ew_UploadPathEx(True, "public/"), annunci.foto3.Upload.FileName)
End If
' Field num_locali
Call annunci.num_locali.SetDbValue(annunci.num_locali.CurrentValue, Null)
rs("num_locali") = annunci.num_locali.DbValue
' Field idtipoimmobile
Call annunci.idtipoimmobile.SetDbValue(annunci.idtipoimmobile.CurrentValue, Null)
rs("idtipoimmobile") = annunci.idtipoimmobile.DbValue
' Field balcone
Call annunci.balcone.SetDbValue(annunci.balcone.CurrentValue, Null)
rs("balcone") = annunci.balcone.DbValue
' Field condizioni
Call annunci.condizioni.SetDbValue(annunci.condizioni.CurrentValue, Null)
rs("condizioni") = annunci.condizioni.DbValue
' Field prezzo
Call annunci.prezzo.SetDbValue(annunci.prezzo.CurrentValue, Null)
rs("prezzo") = annunci.prezzo.DbValue
' Field annocostruzione
Call annunci.annocostruzione.SetDbValue(annunci.annocostruzione.CurrentValue, Null)
rs("annocostruzione") = annunci.annocostruzione.DbValue
' Check recordset update error
If Err.Number <> 0 Then
Session(EW_SESSION_MESSAGE) = Err.Description
rs.Close
Set rs = Nothing
AddRow = False
Exit Function
End If
' Call Row Inserting event
bInsertRow = annunci.Row_Inserting(rs)
If bInsertRow Then
' Field foto1
If Not IsNull(annunci.foto1.Upload.Value) Then Call ew_SaveFile(ew_UploadPathEx(True, "public/"), rs("foto1"), annunci.foto1.Upload.Value)
' Field foto2
If Not IsNull(annunci.foto2.Upload.Value) Then Call ew_SaveFile(ew_UploadPathEx(True, "public/"), rs("foto2"), annunci.foto2.Upload.Value)
' Field foto3
If Not IsNull(annunci.foto3.Upload.Value) Then Call ew_SaveFile(ew_UploadPathEx(True, "public/"), rs("foto3"), annunci.foto3.Upload.Value)
' Clone new rs object
Set rsnew = ew_CloneRs(rs)
rs.Update
If Err.Number <> 0 Then
Session(EW_SESSION_MESSAGE) = Err.Description
AddRow = False
Else
AddRow = True
End If
Else
rs.CancelUpdate
If annunci.CancelMessage <> "" Then
Session(EW_SESSION_MESSAGE) = annunci.CancelMessage
annunci.CancelMessage = ""
Else
Session(EW_SESSION_MESSAGE) = "Insert cancelled"
End If
AddRow = False
End If
rs.Close
Set rs = Nothing
If AddRow Then
annunci.idappartamenti.DbValue = rsnew("idappartamenti")
' Call Row Inserted event
Call annunci.Row_Inserted(rsnew)
End If
' Field foto1
Call annunci.foto1.Upload.RemoveFromSession() ' Remove file value from Session
' Field foto2
Call annunci.foto2.Upload.RemoveFromSession() ' Remove file value from Session
' Field foto3
Call annunci.foto3.Upload.RemoveFromSession() ' Remove file value from Session
If IsObject(rsnew) Then
rsnew.Close
Set rsnew = Nothing
End If
End Function
%>
Spero che questo pezzo di codice sia sufficiente a capire dov'è il problema.