How to binding SfSchedule with Database

Hi there,
I am very new with syncfusion, I have some question need you guys to help.
1. How to set up a database for SfSchedule.
2. How to binding two way with SfSchedule. like when a client wants to add, update, delete it will auto-update in the database
also if you guys have any previous work with that please send me the demo it will clear my mind.

many thanks

Anh

1 Reply

DY Deivaselvan Y Syncfusion Team August 17, 2018 05:28 AM UTC

  
You can add new Database connection by clicking add icon button in Server Explorer. The Add Connection wizard appeared with the default data source as Microsoft SQL Server Database File (SqlClient). Click Change to open the Change Data Source dialog box and select the type of data source   
that you have owned. We have used Microsoft SQL Server (SqlClient). You can also use MySQL database kindly refer the below link to connect the MySQL,  
  
  
In the Server name option, click the Refresh button to select the server from the drop down list. Enable select or enter a database name radio button to select database from the drop down list under the Connect to a database option. You can refer the below link to create a database in SQL server.  
  
  
Click Test Connection to check whether the connection with your database is succeeded or not. Once the connection is succeeded, click OK button to add database in your server explorer.  
  
   
  
Drag Meeting_Table table in to design view of MeetingDB.dbml. The Entity model diagram for Meeting table is generated once it is dropped in to design view. You can enter the values in the Meeting_Table by using Show Table Data option. We have maintained the meeting details as string in the database.    
  
You can load the database created in previous step in to SfSchedule by using MeetingsDBDataContext and it can be mapped to the custom appointments of schedule. You can refer the below link regarding the schedule and custom appointments and mapping method.  
   
  
Code snippet:  
            MeetingsDBDataContext = new MeetingsDBDataContext();  
            var MeetingsList = (from data in MeetingsDBDataContext.Meeting_Tables  
                                select data).ToList();  
  
            for (int i = 0; i < MeetingsList.Count; i++)  
            {  
                Meetings.Add(new ScheduleMeeting()  
                {  
                    MappedSubject = MeetingsList[i].Subject,  
                    MappedStartTime = Convert.ToDateTime(MeetingsList[i].StartTime),  
                    MappedEndTime = Convert.ToDateTime(MeetingsList[i].EndTime),  
                    MappedColor = newSolidColorBrush((Color)ColorConverter.ConvertFromString(MeetingsList[i].Color)),  
                    MappedIsAllDay = Convert.ToBoolean(MeetingsList[i].IsAllDay),  
                    AppointmentID = MeetingsList[i].ID.ToString()  
                });  
            }  
  
You can also add, update and delete the data in database by using MeetingsDBDataContext and Meeting_Table in AppointmentEditorClosed event where you can get the edited appointment details. Kindly refer the below code snippet.   
  
Code snippet:  
        private void Schedule_AppointmentEditorClosed(object sender, AppointmentEditorClosedEventArgs e)  
        {  
  
            MeetingsDBDataContext scheduleMeetings = new MeetingsDBDataContext();  
            Meeting_Table meeting;  
             
  
            if (e.Action == EditorClosedAction.Save)  
            {  
                var editedAppointment = (e.EditedAppointment as ScheduleMeeting);  
                var appointmentID = Convert.ToInt32(editedAppointment.AppointmentID);  
  
                if (!e.IsNew)  
                {  
                    meeting = (from data in scheduleMeetings.Meeting_Tables  
                                   where data.ID == appointmentID  
                                   select data).First() as Meeting_Table;  
  
                    meeting.Subject = editedAppointment.MappedSubject;  
                    meeting.StartTime = editedAppointment.MappedStartTime.ToString();  
                    meeting.EndTime = editedAppointment.MappedEndTime.ToString();  
                    meeting.Color = editedAppointment.MappedColor.ToString();  
                    meeting.IsAllDay = editedAppointment.MappedIsAllDay.ToString();  
                    meeting.ID = appointmentID;  
                }  
                else  
                {  
                    meeting = new Meeting_Table();  
  
                    meeting.Subject = editedAppointment.MappedSubject;  
                    meeting.StartTime = editedAppointment.MappedStartTime.ToString();  
                    meeting.EndTime = editedAppointment.MappedEndTime.ToString();  
                    meeting.Color = editedAppointment.MappedColor.ToString();  
                    meeting.IsAllDay = editedAppointment.MappedIsAllDay.ToString();  
                    meeting.ID = appointmentID;  
  
                    scheduleMeetings.Meeting_Tables.InsertOnSubmit(meeting);  
                }                 
                scheduleMeetings.SubmitChanges();  
            }  
  
            if (e.Action == EditorClosedAction.Delete)  
            {  
                var editedAppointment = (e.OriginalAppointment as ScheduleMeeting);  
                var appointmentID = Convert.ToInt32(editedAppointment.AppointmentID);  
  
                meeting = (from data in scheduleMeetings.Meeting_Tables  
                           where data.ID == appointmentID  
                           select data).First() as Meeting_Table;  
  
                scheduleMeetings.Meeting_Tables.DeleteOnSubmit(meeting);  
                scheduleMeetings.SubmitChanges();  
            }  
  
        }  
    }  
  
Sample: SfSchedule  
  
Please let us know if you need further assistance on this.  

Regards,
Deivaselvan 


Loader.
Up arrow icon