vb统计一段时间内的总量时出现问题,高手来看下...

来源:百度知道 编辑:UC知道 时间:2024/09/23 23:28:08
先贴上代码来..
Private Sub cmdFree_Click()
Dim inTtotle As Integer, outTotle As Integer
On Error GoTo Err

Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & gFile & ";Mode=ReadWrite;Persist Security Info=False"
Adodc1.CommandType = adCmdText

Adodc1.RecordSource = "select sum(收入) as inTotle from 收支表 where 日期 between #" & Text4.Text & "# and #" & Text5.Text & "#"
Adodc1.Refresh
txtSum(0).Text = Adodc1.Recordset("inTotle")

Adodc1.RecordSource = "select sum(支出) as outTotle from 收支表 where 日期 between #" & Text4.Text & "# and #" & Text5.Text & "#"
Adodc1.Refresh
txtSum(1).Text = Adodc1.Recordset("outTotle")

Exit Sub
Err:
MsgBox ("没有搜索指定日期间的数据!")
End Sub

功能是查询从text4和text5中输入的两个时间段内收入支出的总和...但查询出的结果明

text4和text5的值是字符,程序要的是date值,用cdate().
比如,将text4.text换成cdate(text4.text)
将text5.text换成cdate(text5.text)

在处理数据时最大的忌讳是用默认数据类型,最好是进行数据类型的定义。