0

我试图让用户在文本框中输入年份,如果数据库中存在年份(其中有学期的特定日期),它会在日历中显示这些日期。

我已经寻找了几天如何做到这一点,但我找不到任何帮助。

这甚至可能吗?我希望能够为此使用 SQLDataSource,但我无法将连接字符串添加到日历中。

任何帮助都会很棒!标记

*已修订* * ** 我的数据库中有一个表格,其中包含每个大学学期的开始日期和结束日期,例如秋季、春季、夏季以及复活节假期。我希望用户能够输入他们希望更改日期的年份并点击搜索按钮。如果数据库有输入年份的记录,则会显示每个日期的日历,从数据库中选择日期,而不是当前日期。

4

1 回答 1

0

终于弄清楚如何将数据库中设置的日期显示在日历中。这是代码:

        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
于 2013-04-22T16:05:39.723 回答