Dim cmd As New SQLCommand
Dim dt As DataTable
cmd.CommandText = "SELECT DISTINCT Year(dhrq) As 年, Month(dhrq) As 月, day(dhrq) As 日 From {cghd}"
dt = cmd.ExecuteReader()
Dim trv As WinForm.TreeView = e.Form.Controls("TreeView1")
trv.BuildTree(dt, "年|月|日")
Dim Value() As String
Dim Filter As String
Dim d1 As Date
Dim d2 As Date
Value = e.Node.FullPath.Split("\")
Select Case e.Node.Level
Case 0
Dim y As Integer = value(0)
d1 = New Date(y,1,1)
d2 = new Date(y,12,31)
Filter = "dhrq >= #" & d1 & "# And dhrq <= #" & d2 & "#"
Case 1
Dim y As Integer = value(0)
Dim m As Integer = value(1)
d1 = New Date(y, m, 1)
d2 = new Date(y, m, Date.DaysInMonth(y,m))
Filter = "dhrq >= #" & d1 & "# And dhrq <= #" & d2 & "#"
Case 2
Dim y As Integer = value(0)
Dim m As Integer = value(1)
Dim d As Integer = value(2)
d1 = New Date(y, m, d)
Filter = "dhrq = #" & d1 & "# "
End Select
Tables("cghd").Filter = Filter
[此贴子已经被作者于2013-7-10 16:58:28编辑过]