vb with rs 查询

来源:百度知道 编辑:UC知道 时间:2024/05/27 09:40:37
数据库名:lwl.mdb
表名:lwl
字段:收入,投资,资金库存,支出
现在就是查询这几个字段的和,分别显示在text1、text2、text3、text4

Private Sub command1_click()
Dim cn As New adodb.Connection '* 数据库连接
Dim rs As New adodb.Recordset '* 数据库记录

'* 连接数据库源
cn.CursorLocation = adUseClient
cn.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & App.Path & "\lwl.mdb"

rs.Open "SELECT * FROM lwl", cn, _
adOpenDynamic, adLockOptimistic, adCmdText

With rs
这中间的怎么写

End With

把以下语句包在 with rs .... end with 里面,试验了没问题。
text1.text=empty
text2.text=empty
text3.text=empty
text4.text=empty

do while not .eof
text1.text = val(text1.text ) + !收入
text2.text = val(text2.text ) + !投资
text3.text = val(text3.text ) + !资金库存
text4.text = val(text4.text ) + !支出
.movenext
loop