终于弄清楚如何将数据库中设置的日期显示在日历中。这是代码:
Dim strConn As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\scrummingit2.mdf;Integrated Security=True;User Instance=True"
Dim sql As String = "SELECT [Year], [Autumn_Start], [Autumn_End], [Spring_Start], [Spring_End], [Summer_Start], [Summer_End], [Easter_Start], [Easter_End] FROM [Semester_Dates] WHERE ([Year] = '" + TxtAddYearDates.Text + "')"
Dim conn As New SqlConnection(strConn)
Dim objDR As SqlDataReader
Dim Cmd As New SqlCommand(Sql, conn)
conn.Open()
objDR = Cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
While objDR.Read()
AutumnStartCalendar.SelectedDate = objDR("Autumn_Start")
AutumnStartCalendar.VisibleDate = objDR("Autumn_Start")
AutumnEndCalendar.SelectedDate = objDR("Autumn_End")
AutumnEndCalendar.VisibleDate = objDR("Autumn_End")
SpringStartCalendar.SelectedDate = objDR("Spring_Start")
SpringStartCalendar.VisibleDate = objDR("Spring_Start")
SpringEndCalendar.SelectedDate = objDR("Spring_End")
SpringEndCalendar.VisibleDate = objDR("Spring_End")
SummerStartCalendar.SelectedDate = objDR("Summer_Start")
SummerStartCalendar.VisibleDate = objDR("Summer_Start")
SummerEndCalendar.SelectedDate = objDR("Summer_End")
SummerEndCalendar.VisibleDate = objDR("Summer_End")
EasterStartCalendar.SelectedDate = objDR("Easter_Start")
EasterStartCalendar.VisibleDate = objDR("Easter_Start")
EasterEndCalendar.SelectedDate = objDR("Easter_End")
EasterEndCalendar.VisibleDate = objDR("Easter_End")
End While