Skip to content

DevExpress-Examples/winforms-scheduler-bind-to-ms-sql-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WinForms Scheduler - Bind to MS SQL Server (runtime)

This example shows how to bind the SchedulerControl to a MS SQL Server database at runtime. The SqlCommandBuilder class is used to generate SQL queries.

The example uses the MS SQL Server database. You can create a new database using the .sql script file included in the project, or connect to another database. Check the code that specifies mappings to ensure that all data fields are correctly mapped to appointment properties.

In this example:

  • Define mappings.

    The UniqueID field in the Appointments table is not mapped because it is an identity auto-incremented field updated by MS SQL Sever. If you map it, make sure that the AppointmentStorage.CommitIdToDataSource option is disabled.

    private void MapAppointmentData() {
        this.schedulerDataStorage1.Appointments.Mappings.AllDay = "AllDay";
        this.schedulerDataStorage1.Appointments.Mappings.Description = "Description";
        // Required mapping.
        this.schedulerDataStorage1.Appointments.Mappings.End = "EndDate";
        this.schedulerDataStorage1.Appointments.Mappings.Label = "Label";
        this.schedulerDataStorage1.Appointments.Mappings.Location = "Location";
        this.schedulerDataStorage1.Appointments.Mappings.RecurrenceInfo = "RecurrenceInfo";
        this.schedulerDataStorage1.Appointments.Mappings.ReminderInfo = "ReminderInfo";
        // Required mapping.
        this.schedulerDataStorage1.Appointments.Mappings.Start = "StartDate";
        this.schedulerDataStorage1.Appointments.Mappings.Status = "Status";
        this.schedulerDataStorage1.Appointments.Mappings.Subject = "Subject";
        this.schedulerDataStorage1.Appointments.Mappings.Type = "Type";
        this.schedulerDataStorage1.Appointments.Mappings.ResourceId = "ResourceIDs";
        this.schedulerDataStorage1.Appointments.CustomFieldMappings.Add(new AppointmentCustomFieldMapping("MyNote", "CustomField1"));
    }
  • Set the ResourceSharing property to true to assign multiple resources to appointments.

    this.schedulerDataStorage1.Appointments.ResourceSharing = true;

    If the ResourceSharing property is set to false (the default value), the AppointmentMappingInfo.ResourceId property should be set to the database field that contains the value of the resource ID that is associated with the appointment. This field must contain values of the same type as the resource ID. The Scheduler control does not restrict the type of resource ID to a particular .NET type. You can use any data type if the types of corresponding fields in Appointment and Resource data tables match.

If your database server is not MS SQL, you can replace SqlDataAdapter and SqlCommandBuilder with another data adapter and command builder (for example, OracleDataAdapter and OracleCommandBuilder).

Documentation

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)