如何从vb6中的访问中检索记录 [英] how to retrieve records from access in vb6

查看:96
本文介绍了如何从vb6中的访问中检索记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Dim Con As New ADODB.Connection

Dim rs As New ADODB.Recordset

Dim s As字符串

Private Sub Command1_Click()

Con.Open s

rs.OpenSELECT * FROM TRAIN WHERE FROM LIKE& Combo1.Text& %'并且喜欢'& Combo2.Text& %',Con,adOpenDynamic,adLockOptimistic

如果rs.EOF = False那么

Text3.Text = rs(0)

Text4 .Text = rs(1)

Text6.Text = rs(2)

Text7.Text = rs(3)

Text5.Text = rs(4)

结束如果



rs.Close

Con.Close

结束次级









这是正确与否....我有一个问题,第一条记录显示剩余的9条记录未显示在输出中。

请帮助我

Dim Con As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim s As String
Private Sub Command1_Click()
Con.Open s
rs.Open "SELECT * FROM TRAIN WHERE FROM LIKE '" & Combo1.Text & "%' AND TO LIKE '" & Combo2.Text & "%' ", Con, adOpenDynamic, adLockOptimistic
If rs.EOF = False Then
Text3.Text = rs(0)
Text4.Text = rs(1)
Text6.Text = rs(2)
Text7.Text = rs(3)
Text5.Text = rs(4)
End If

rs.Close
Con.Close
End Sub




This is correct or not.... i have a problem with 1st record is displayed remaining 9 records are not displayed in the output.
please help me

推荐答案

Dim Con As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim s As String

Private Sub Command1_Click()
Con.Open s
rs.Open "SELECT * FROM TRAIN WHERE FROM LIKE '" & Combo1.Text & "%' AND TO LIKE '" & Combo2.Text & "%' ", Con, adOpenDynamic, adLockOptimistic

While Not rs.EOF
      Text3.Text = rs(0)
      Text4.Text = rs(1)
      Text6.Text = rs(2)
      Text7.Text = rs(3)
      Text5.Text = rs(4)
      rs.MoveNext
Wend





注意:在UI上,当你在每次迭代中使用新记录编写Text.Text时,你将得到最后记录的值。



Note : On the UI you will get the values of last records as you are over writing the Text.Text with new record in each iteration.


参考: Visual Basic 6 ADO教程 [ ^ ]


这篇关于如何从vb6中的访问中检索记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆