Imports Telerik.WinControls.UI Public Class Form1 Dim appointmentsTableAdapter As New SchedulerDataSetTableAdapters.AppointmentsTableAdapter Dim resourcesTableAdapter As New SchedulerDataSetTableAdapters.ResourcesTableAdapter Dim appointmentsResourcesTableAdapter As New SchedulerDataSetTableAdapters.AppointmentsResourcesTableAdapter Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Dim appointmentMappingInfo As AppointmentMappingInfo = New AppointmentMappingInfo() appointmentMappingInfo.BackgroundId = "BackgroundId" appointmentMappingInfo.Description = "Description" appointmentMappingInfo.[End] = "End" appointmentMappingInfo.Location = "Location" appointmentMappingInfo.MasterEventId = "MasterEventId" appointmentMappingInfo.RecurrenceRule = "RecurrenceRule" appointmentMappingInfo.ResourceId = "ResourceID" appointmentMappingInfo.Exceptions = "Appointments_Appointments" appointmentMappingInfo.Resources = "AppointmentsResources_Appointments" appointmentMappingInfo.Start = "Start" appointmentMappingInfo.StatusId = "StatusID" appointmentMappingInfo.Summary = "Summary" appointmentMappingInfo.Visible = "Visible" SchedulerBindingDataSource1.EventProvider.Mapping = appointmentMappingInfo Dim resourceMappingInfo As ResourceMappingInfo = New ResourceMappingInfo() resourceMappingInfo.Id = "ID" resourceMappingInfo.Name = "Name" Me.SchedulerBindingDataSource1.ResourceProvider.Mapping = resourceMappingInfo SchedulerBindingDataSource1.ResourceProvider.DataSource = SchedulerDataSet.Resources SchedulerBindingDataSource1.EventProvider.DataSource = SchedulerDataSet.Appointments RadScheduler1.DataSource = SchedulerBindingDataSource1 Me.RadScheduler1.GroupType = GroupType.Resource appointmentsTableAdapter.Fill(SchedulerDataSet.Appointments) ResourcesTableAdapter.Fill(SchedulerDataSet.Resources) AppointmentsResourcesTableAdapter.Fill(SchedulerDataSet.AppointmentsResources) cmdSave.Enabled = True End Sub Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click save1() End Sub Private Sub save1() appointmentsResourcesTableAdapter.Adapter.AcceptChangesDuringUpdate = False Dim deletedRelationRecords As SchedulerDataSet.AppointmentsResourcesDataTable = TryCast(Me.SchedulerDataSet.AppointmentsResources.GetChanges(DataRowState.Deleted), SchedulerDataSet.AppointmentsResourcesDataTable) Dim newRelationRecords As SchedulerDataSet.AppointmentsResourcesDataTable = TryCast(Me.SchedulerDataSet.AppointmentsResources.GetChanges(DataRowState.Added), SchedulerDataSet.AppointmentsResourcesDataTable) Dim modifiedRelationRecords As SchedulerDataSet.AppointmentsResourcesDataTable = TryCast(Me.SchedulerDataSet.AppointmentsResources.GetChanges(DataRowState.Modified), SchedulerDataSet.AppointmentsResourcesDataTable) Dim newAppointmentRecords As SchedulerDataSet.AppointmentsDataTable = TryCast(Me.SchedulerDataSet.Appointments.GetChanges(DataRowState.Added), SchedulerDataSet.AppointmentsDataTable) Dim deletedAppointmentRecords As SchedulerDataSet.AppointmentsDataTable = TryCast(Me.SchedulerDataSet.Appointments.GetChanges(DataRowState.Deleted), SchedulerDataSet.AppointmentsDataTable) Dim modifiedAppointmentRecords As SchedulerDataSet.AppointmentsDataTable = TryCast(Me.SchedulerDataSet.Appointments.GetChanges(DataRowState.Modified), SchedulerDataSet.AppointmentsDataTable) Try If newAppointmentRecords IsNot Nothing Then Dim newAppointmentIds As Dictionary(Of Integer, Integer) = New Dictionary(Of Integer, Integer)() Dim oldAppointmentIds As Dictionary(Of Object, Integer) = New Dictionary(Of Object, Integer)() For i As Integer = 0 To newAppointmentRecords.Count - 1 oldAppointmentIds.Add(newAppointmentRecords(i), newAppointmentRecords(i).ID) Next appointmentsTableAdapter.Update(newAppointmentRecords) For i As Integer = 0 To newAppointmentRecords.Count - 1 newAppointmentIds.Add(oldAppointmentIds(newAppointmentRecords(i)), newAppointmentRecords(i).ID) Next If newRelationRecords IsNot Nothing Then For i As Integer = 0 To newRelationRecords.Count - 1 newRelationRecords(i).AppointmentID = newAppointmentIds(newRelationRecords(i).AppointmentID) Next End If End If If deletedRelationRecords IsNot Nothing Then appointmentsResourcesTableAdapter.Update(deletedRelationRecords) End If If deletedAppointmentRecords IsNot Nothing Then appointmentsTableAdapter.Update(deletedAppointmentRecords) End If If modifiedAppointmentRecords IsNot Nothing Then MsgBox("*** before Error") appointmentsTableAdapter.Update(modifiedAppointmentRecords) End If If newRelationRecords IsNot Nothing Then appointmentsResourcesTableAdapter.Update(newRelationRecords) End If If modifiedRelationRecords IsNot Nothing Then appointmentsResourcesTableAdapter.Update(modifiedRelationRecords) End If Me.SchedulerDataSet.AcceptChanges() Catch ex As Exception MessageBox.Show(String.Format("An error occurred during the update process:" & vbLf & "{0}", ex.Message)) Finally If deletedRelationRecords IsNot Nothing Then deletedRelationRecords.Dispose() End If If newRelationRecords IsNot Nothing Then newRelationRecords.Dispose() End If If modifiedRelationRecords IsNot Nothing Then modifiedRelationRecords.Dispose() End If End Try End Sub End Class