Category / Section
How to bind the SQL data with WinForms ScheduleControl?
1 min read
Bind SQL data with Schedule
By default, the ScheduleControl does not have the direct support to bind data from SQL server. To get direct support to bind data from SQL server, the schedule control should be bound with ScheduleDataProvider data source, and the appointments should be processed using the ScheduleAppointment. So, generate the ScheduleAppointment manually based on the retrieved data from SQL database.
C#
SimpleScheduleDataProvider dataProvider = new SimpleScheduleDataProvider();
SimpleScheduleAppointmentList list = new SimpleScheduleAppointmentList();
dataProvider.MasterList = list;
scheduleControl1.DataSource = dataProvider;
SqlConnection con = new SqlConnection(ConnectionString);
string sql = "select * from ScheduleData";
con.Open();
SqlCommand cmd = new SqlCommand(sql, con);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
ScheduleAppointment item = new ScheduleAppointment();
item.UniqueID = (int)dr["UniqueID"];
item.Subject = (string)dr["Sub"];
item.StartTime = (DateTime)dr["StartTime"];
item.ReminderValue = (int)dr["ReminderValue"];
item.Reminder = false;
item.Owner = (int)dr["Own"];
item.MarkerValue = (int)dr["MarkerValue"];
item.LocationValue = (string)dr["LocationValue"];
item.LabelValue = 0;
item.EndTime = (DateTime)dr["EndDate"];
item.Content = (string)dr["Content"];
item.AllDay = false;
item.Dirty = false;
list.Add(item);
}
Note:
To work with SQL data at client machine, modify the connection string by creating a data base using the SQL Express, and then add the table “ScheduleData” like the attached local database file in sample.
Sample: SQL database to ScheduleControl
Did not find the solution
Contact Support