Example E551
Visible to All Users

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.
    C#
    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.
    C#
    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)

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.