0

I want to delete appointment from list but I don't wont deteled that from my database. I use this code but it doesn't work.

Private Sub schedulerControl_DeleteAppointmentFormShowing(sender As Object, e As AppointmentFormEventArgs) Handles schedulerControl.DeleteRecurrentAppointmentFormShowing
    Dim scheduler As DevExpress.XtraScheduler.SchedulerControl = CType(sender, DevExpress.XtraScheduler.SchedulerControl)
    Try
        If koneksiDB.State = ConnectionState.Open Then
            'proses simpan DB
            Dim cmd As New SqlCommand("update Appointments set isdeleted = 1 where UniqueID = @Kode", koneksiDB)
            Dim apt As Appointment = schedulerControl.SelectedAppointments(0)
            Dim dr As DataRowView = CType(apt.GetSourceObject(schedulerStorage), DataRowView)
            Dim id As Integer = Convert.ToInt64(dr("UniqueID"))
            cmd.Parameters.AddWithValue("kode", id)
            cmd.ExecuteNonQuery()
            RefreshDB()
        Else
            MsgBox("Maaf koneksi dengan database terputus. harap memperbaiki koneksi terlebih dahulu.")
        End If
    Catch ex As Exception
        MsgBox("Maaf, terjadi permasalahan teknis :" & Chr(13) & ex.Message & Chr(13) & Chr(13) & "Silakan catat dan hubungi pihak teknisi bila diperlukan.", MsgBoxStyle.Exclamation)
    End Try
End Sub
Martin Verjans
  • 4,675
  • 1
  • 21
  • 48

1 Answers1

0

The line where you add the parameter:

cmd.Parameters.AddWithValue("kode", id)

you should add the @ character and a capital K letter :

cmd.Parameters.AddWithValue("@Kode", id)

The @ character is not necessary but considered best practices. However I think it is case sensitive, so don't forget the capital K.

See this question for more details (Is it necessary to add a @ in front of an SqlParameter name?).

Martin Verjans
  • 4,675
  • 1
  • 21
  • 48