如何获取指定年份的月份
在Access数据库有很多根据年月日填写的数据,如何根据年来获取当年来保存的所有月的记录,然后保存起来!怎么做呢?请各位大侠帮帮忙! --------------------编程问答-------------------- 你的意思是列出各年中有记录的月份吗?select ditinct year(datefileld) as 年份, month(datefield) as 月份 from yourtable order by year(datefileld), month(datefield) --------------------编程问答-------------------- 谢谢你了! 不过我还是不明白怎么做。
date time define
2005-09-08 18:00:35 报警
2005-11-05 10:41:32 已消除
2006-09-14 09:55:40 报警
2006-11-05 10:42:31 报警
2007-02-14 15:57:07 已消除
比如它数据库中的值是这样子的
我现在要做一个查询,三个组合框,分别代表年、月、日
现在基本上是做出来了,不过我点击2005年时,月的组合框里出现了
02月、09月、11月,02月是它没有,我想点击哪一年时,月那里就出现
它自己有的那几个月,不要把数据库所有的月都包括进去!
希望各位大侠帮帮忙! --------------------编程问答-------------------- Private Sub Form1_Load()
Dim cn As New ADODB.Connection, rs As New ADODB.Recordset
cn.Open "......"
set rs = cn.execute ("select ditinct year([date]) from yourtable order by year([date])")
Do Until rs.EOF
Combo1.Add rs.Fields(0)
rs.MoveNext
Loop
If Combo1.ListCount Then Combo1.ListIndex = 0
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub
Private Sub Combo1_Click()
Dim cn As New ADODB.Connection, rs As New ADODB.Recordset
cn.Open "......"
set rs = cn.execute ("select ditinct Month([date]) from yourtable where year([date])=" & Combo1.Text & " order by Month([date])")
Combo2.Clear
Do Until rs.EOF
Combo2.Add rs.Fields(0)
rs.MoveNext
Loop
If Combo2.ListCount Then Combo2.ListIndex = 0
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub
Private Sub Combo2_Click()
Dim cn As New ADODB.Connection, rs As New ADODB.Recordset
cn.Open "......"
set rs = cn.execute ("select ditinct Day([date]) from yourtable where year([date])=" & Combo1.Text & " and Month([date])=" & Combo2.Text & " order by Day([date])")
Combo3.Clear
Do Until rs.EOF
Combo3.Add rs.Fields(0)
rs.MoveNext
Loop
If Combo3.ListCount Then Combo2.ListIndex = 0
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub
--------------------编程问答-------------------- year([date]),Month([date]),Day([date]) 分别应该怎么填啊?
补充:VB , 数据库(包含打印,安装,报表)