VB数据库问题我是个菜鸟正在自学
登录代码:
Option Explicit
Dim yonghu As String
Dim mima As String
Private Sub cmdOK_Click()
'检查正确的密码
If txtPassword = mima And txtUserName = yonghu Then
'将代码放在这里传递
Form2。 Show
Form2。Label1。Caption = "登录成功!"
Else
MsgBox "无效的密码,请重试!", , "登录"
txtPassword。 SetFocus
SendKeys "{Home}+{End}"
End If
End Sub...全部
登录代码:
Option Explicit
Dim yonghu As String
Dim mima As String
Private Sub cmdOK_Click()
'检查正确的密码
If txtPassword = mima And txtUserName = yonghu Then
'将代码放在这里传递
Form2。
Show
Form2。Label1。Caption = "登录成功!"
Else
MsgBox "无效的密码,请重试!", , "登录"
txtPassword。
SetFocus
SendKeys "{Home}+{End}"
End If
End Sub
Private Sub Form_Load()
'连接数据库存放用户名密码的表
Adodc1。
ConnectionString = "Provider=Microsoft。Jet。OLEDB。4。0;Data Source=D:\data_ref\ b;Persist Security Info=False"
Adodc1。
RecordSource = "select * from ps"
Adodc1。Refresh
yonghu = Adodc1。Recordset(0) '传递用户名
mima = Adodc1。
Recordset(1) '传递密码
End Sub
修改部分的代码:
Option Explicit
Dim yonghu As String
Dim mima As String
Dim ym As Variant
Private Sub cmdOK_Click()
ym = MsgBox("修改用户名密码!", vbOK, "修改") '
If ym = vbOK Then
Adodc1。
Recordset(0) = Text1 '传递新用户名
Adodc1。Recordset(1) = Text2 '传递新密码
Adodc1。Recordset。
Update '修改数据处理
Form2。Show
Form2。Label1。Caption = "成功修改用户名和密码!"
Else
Unload Me
End If
End Sub
Private Sub Form_Load()
Text1 = "": Text2 = ""
Adodc1。
ConnectionString = "Provider=Microsoft。Jet。OLEDB。4。0;Data Source=D:\data_ref\ b;Persist Security Info=False"
Adodc1。
RecordSource = "select * from ps"
Adodc1。Refresh
yonghu = Adodc1。Recordset(0)
mima = Adodc1。
Recordset(1)
End Sub
Private Sub txtPassword_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 And txtPassword = mima Then '核实原密码
Text1。
Enabled = True
Text2。Enabled = True
Text1。SetFocus
End If
End Sub
Private Sub txtUserName_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 And txtUserName = yonghu Then '核实原用户名
txtPassword。
SetFocus
End If
End Sub
工程文件附后上传。
DB4。MDB数据库存放D:\DATA_REF目录夹,原用户名和密码分别为:user和111111
祝你学习成功!。
收起