Problema con query Update

di il
0 risposte

Problema con query Update

Con la seguente query con parametri vorrei aggiornare una tabella.

Nella tabella sono già inseriti l'ambulatorio, la Data e l'Orario questi ultimi nel formato data/ora.

   Dim dataInput As Date
    Dim oraInput As Date
    Dim dataOra As Date

   
  
    sTabella = "Diario"
   
    dataInput = CDate(txtData.Text)
    oraInput = CDate(txtTime.Text)
    dataOra = DateValue(dataInput) + TimeValue(oraInput)
    
    sSQL = " UPDATE " & sTabella & " SET"
         sSQL = sSQL & " Visita = @Visita"
         sSQL = sSQL & " ,Ambulatorio=@Ambulatorio"
         sSQL = sSQL & " ,Data = @Data"
         sSQL = sSQL & " ,Orario = @Orario"
         sSQL = sSQL & " ,tVisita=@tVisita"
         sSQL = sSQL & " ,Cognome= @Cognome"
         sSQL = sSQL & " ,Nome = @Nome"
         sSQL = sSQL & " ,Sesso = @Sesso"
         sSQL = sSQL & " ,Nota=@Nota"
         sSQL = sSQL & " ,Telefono = @Telefono"
         sSQL = sSQL & " ,CodiceEs = @CodiceEs"
         sSQL = sSQL & " ,Terapia=@Terapia"
         sSQL = sSQL & " ,Comune=@Comune"
         sSQL = sSQL & " WHERE Ambulatorio=" & Val(lblAmbulatorio.Caption)
         sSQL = sSQL & " And Data = #" & Format(dataOra, "MM/dd/yyyy HH:nn:ss") & "#"
     
       Set cmd = New ADODB.Command
    With cmd
        .ActiveConnection = cn
        .CommandType = adCmdText
        .CommandText = sSQL
        
        SetADOParameter cmd, sTabella, "Visita", "A"
        SetADOParameter cmd, sTabella, "Ambulatorio", lblAmbulatorio.Caption
        SetADOParameter cmd, sTabella, "Data", txtData.Text
        SetADOParameter cmd, sTabella, "Orario", Format(txtTime.Text, "hh:nn:ss")
        SetADOParameter cmd, sTabella, "tVisita", cboTVisita.Text
        SetADOParameter cmd, sTabella, "Cognome", txtCognome.Text
        SetADOParameter cmd, sTabella, "Nome", txtNome.Text
        SetADOParameter cmd, sTabella, "Sesso", txtSesso.Text
        SetADOParameter cmd, sTabella, "Nota", txtNote.Text
        SetADOParameter cmd, sTabella, "Telefono", txtTelefono.Text
        SetADOParameter cmd, sTabella, "CodiceEs", txtCodiceEs.Text
        SetADOParameter cmd, sTabella, "Terapia", cboTerapie.Text
        SetADOParameter cmd, sTabella, "Comune", txtComune.Text
        
         cmd.Execute
    End With
    
     MsgBox "Dati Inseriti!", vbExclamation, Me.Caption
             
      frmDiario.Enabled = True
      frmDiario.CaricaFlex
      frmDiario.Show
      Unload Me

Arriva sino in fondo (msgbox visualizzata), ma di fatto non aggiorna il record.

Se elimino dalla query il campo Orario ( che è ASSOLUTAMENTE necessario) funziona. 

Quindi suppongo che il problema sia proprio lì.

Pubblico pure  Debug.Print  (perfetto!).

Grazie.

UPDATE Diario SET Visita = @Visita ,Ambulatorio=@Ambulatorio ,Data = @Data ,Orario = @Orario ,tVisita=@tVisita ,Cognome= @Cognome ,Nome = @Nome ,Sesso = @Sesso ,Nota=@Nota ,Telefono = @Telefono ,CodiceEs = @CodiceEs ,Terapia=@Terapia ,Comune=@Comune WHERE Ambulatorio=1 And Data = #03/13/2026 19:30:00# 
Devi accedere o registrarti per scrivere nel forum
0 risposte