注册 登录
编程论坛 VB6论坛

新人(求助)求解,数据库和vb中改如何相互调用变量!

雨中花 发布于 2013-07-07 10:44, 377 次点击
假如access这个数据库(code.db)中有5的字段,分别是:用户名,密码,权限,年龄,性别 ;有10条记录

我在窗口中创建了3个text控件,在这个窗口中想显示用户名,年龄,性别。3个按钮控件,上一条 下一条 末条

我应该如赋值呢?在表单加载的时候就显示第一人的用户名,年龄,性别。好像要用到循环语句
该如何编写代码呢?求解,谢谢!
1 回复
#2
LK8682013-07-07 17:49
Private Sub Command1_Click() '下一条记录
Adodc1.Recordset.MoveNext
If Adodc1.Recordset.EOF = True Then Adodc1.Recordset.MoveLast
Text1 = Adodc1.Recordset.Fields("用户名").Value
Text2 = Adodc1.Recordset.Fields("年龄").Value
Text3 = Adodc1.Recordset.Fields("性别").Value

End Sub

Private Sub Command2_Click() '第一条记录
Adodc1.Recordset.MoveFirst
Text1 = Adodc1.Recordset.Fields("用户名").Value
Text2 = Adodc1.Recordset.Fields("年龄").Value
Text3 = Adodc1.Recordset.Fields("性别").Value

End Sub

Private Sub Form_Load()
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\AAA.mdb;Persist Security Info=False;Jet OLEDB:Database Password=1234;"
Adodc1.RecordSource = "select * from 人员 ORDER BY ID"
Adodc1.Refresh
Adodc1.Recordset.MoveFirst
Text1 = Adodc1.Recordset.Fields("用户名").Value
Text2 = Adodc1.Recordset.Fields("年龄").Value
Text3 = Adodc1.Recordset.Fields("性别").Value
End Sub

1