vb中统计一个时间区间的花销总和
Dim dBeginDate As Date
Dim dEndDate As Date
Dim s As Integer
Dim i As Integer
Dim price As Single
Private Sub Command1_Click()
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\数据库\账单信息表(1).mdb;Persist Security Info=False"
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
dBeginDate = Format(CDate(Combo1 & "-" & Combo3 & "-" & Combo4), "yyyy-M-d")
dEndDate = Format(CDate(Combo2 & "-" & Combo5 & "-" & Combo6), "yyyy-M-d")
rs.Open "select 花销 from 表1 where 日期 between # " + dBeginDate + " # And # " + dEndDate + " # ", cn, adOpenDynamic, adLockOptimistic
Set DataGrid1.DataSource = rs
price = 0
While Not rs.EOF
price = price + Val(rs.Fields(0))
rs.MoveNext
Wend
Text1.Text = Format(price, "#0.00")
End Sub
Private Sub Form_Load()
Dim i As Integer
For i = 2010 To Year(Now())
Combo1.AddItem i
Combo2.AddItem i
Next i
For i = 1 To 12
Combo3.AddItem i
Combo5.AddItem i
Next i
For i = 1 To 31
Combo4.AddItem i
Combo6.AddItem i
Next i
黑体部分出现类型不匹配是怎么回事?我都看了一天了,就是没看出问题出在哪里
[解决办法]
你数据库中 表1的日期列是什么数据类型的
[解决办法]
日期型的
[解决办法]
已经告诉你类型不匹配,你还看了一天,说明你对数据库一无所知
[解决办法]
赶快找本书看看