从数据库中禁用日历回溯日期中的选定日期

时间:2015-06-02 12:00:52

标签: database vb.net date calendar

我想使用VB.net做一个日历,当列Date 02/06/2015重复三次然后在日历中禁用相同日期时突出显示/禁用日期,如果少于三日历中没有变化date,从数据库中检索所有这些日期。

_______________________________________________
ID  |     Name     |   IDNo    |     Date     |
-----------------------------------------------
 1  |     A        |  1235     |  02/06/2015  |
 3  |     B        |  1236     |  02/06/2015  |
 4  |     C        |  1237     |  02/06/2015  |
 5  |     D        |  1238     |  03/06/2015  |
 6  |     E        |  1239     |  03/06/2015  |
 7  |     F        |  1240     |  05/06/2015  |
 8  |     G        |  1241     |  05/06/2015  |

1 个答案:

答案 0 :(得分:0)

此代码仅禁用日历中的第一个日期,,,,

Dim sql As String = "Select (Date) From PersonalData Group By date having date>=2"
    Dim command As SqlCommand = New SqlCommand(sql, connection)
    Dim reader As SqlDataReader = command.ExecuteReader()
        If (reader.Read()) Then
            If (reader.HasRows) Then
            While reader.Read()
                Calendar1.SelectedDates.Add(CType(reader.GetDateTime(0), Date))
                Calendar1.SelectedDayStyle.BackColor = System.Drawing.Color.Red
                nextdate = Calendar1.SelectedDate
                If nextdate = e.Day.Date Then
                    e.Cell.Text = "--"
                End If
            End While
            End If
        End If