求VB登陆界面详细代码
要求需要在VB里面做密码,用户名可以登陆,通过所绑定的数据库定义的用户就是说数据库里的用户名跟密码在登陆界面里都可以登陆!需要详细的代码急求哦!!帮忙哦!!!以下是我之前...
要求需要在VB里面做 密码,用户名可以登陆,通过所绑定的数据库定义的用户 就是说数据库里的用户名跟密码在登陆界面里都可以登陆! 需要详细的代码 急求哦!!帮忙哦!!!
以下是我之前做的 人家说只能登陆一个用户 他们需要的是数据库里的用户都可以登陆
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If TextBox1.Text = 777 And TextBox2.Text = 888 Then
MsgBox("登陆成功!") form1.show()
Else
MsgBox("输入错误")
End If
End Sub
End Class
这里我建立了2个BUTTON 2个TEXTBOX 展开
以下是我之前做的 人家说只能登陆一个用户 他们需要的是数据库里的用户都可以登陆
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If TextBox1.Text = 777 And TextBox2.Text = 888 Then
MsgBox("登陆成功!") form1.show()
Else
MsgBox("输入错误")
End If
End Sub
End Class
这里我建立了2个BUTTON 2个TEXTBOX 展开
2个回答
展开全部
1.拖出两个text 两个command 分别命名为:txtUser ,txtPwd ,cmdLoginEnter ,cmdLoginCancel
2.在程序根目录下新建 date.mdb 数据库 表名为:user
字段1为:username 字段2为:pwd 数据库密码为:111
(可根据) Set dbLogin = OpenDatabase(App.Path + "\Data.mdb", False, False, "MS Access;pwd=111") 修改自定义。
3.复制以下代码。
------------
Option Explicit
Dim intTryTimes As Integer
Dim dbLogin As Database
Dim rstLogin As Recordset
Private Sub cmdLoginCancel_Click()
End
End Sub
Private Sub cmdLoginEnter_Click()
If Me.txtUser = "" Then
MsgBox "用户名不能为空!", vbCritical, Me.Caption
Me.txtUser.SetFocus
GoTo ExitSub
ElseIf Me.txtPwd = "" Then
MsgBox "请填写密码!", vbCritical, Me.Caption
Me.txtPwd.SetFocus
GoTo ExitSub
End If
Set rstLogin = dbLogin.OpenRecordset("select * from User where Username='" + Trim(Me.txtUser) + "'")
If rstLogin.RecordCount = 0 Then
MsgBox "用户名填写错误!", vbCritical, "错误"
Me.txtUser.SetFocus
Me.txtUser.SelStart = 0
Me.txtUser.SelLength = Len(Me.txtUser)
GoTo ExitSub
End If
If rstLogin.Fields("Pwd") = Trim(Me.txtPwd) Then
'登陆成功
' userName = Trim(Me.txtUser)
Unload Me
Form1.Show
' Call Sound("Login")
Else
MsgBox "密码错误!", vbCritical, "错误"
Me.txtPwd.SetFocus
Me.txtPwd.SelStart = 0
Me.txtPwd.SelLength = Len(Me.txtPwd)
End If
GoTo ExitSub
ExitSub:
intTryTimes = intTryTimes + 1
If intTryTimes = 4 Then
MsgBox "密码错误!", vbInformation, Me.Caption
End
End If
End Sub
Private Sub Form_Load()
Me.Left = Screen.Width / 2 - Me.Width / 2
Me.Top = Screen.Height / 2 - Me.Height / 2
Me.Caption = "登陆"
intTryTimes = 0
Set dbLogin = OpenDatabase(App.Path + "\Data.mdb", False, False, "MS Access;pwd=111")
' Set rstLogin = dbLogin.OpenRecordset("select Username from User")
' If rstLogin.RecordCount <> 0 Then
' Me.txtUser = rstLogin.Fields("Username")
' End If
Show
Me.txtUser.SetFocus
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set rstLogin = Nothing
dbLogin.Close
End Sub
Private Sub txtPwd_GotFocus()
Me.txtPwd.SelStart = 0
Me.txtPwd.SelLength = Len(Me.txtPwd)
End Sub
Private Sub txtPwd_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Call cmdLoginEnter_Click
End If
End Sub
Private Sub txtUser_GotFocus()
Me.txtUser.SelStart = 0
Me.txtUser.SelLength = Len(Me.txtUser)
End Sub
Private Sub txtUser_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Call cmdLoginEnter_Click
End If
End Sub
--------------
给分吧!
2.在程序根目录下新建 date.mdb 数据库 表名为:user
字段1为:username 字段2为:pwd 数据库密码为:111
(可根据) Set dbLogin = OpenDatabase(App.Path + "\Data.mdb", False, False, "MS Access;pwd=111") 修改自定义。
3.复制以下代码。
------------
Option Explicit
Dim intTryTimes As Integer
Dim dbLogin As Database
Dim rstLogin As Recordset
Private Sub cmdLoginCancel_Click()
End
End Sub
Private Sub cmdLoginEnter_Click()
If Me.txtUser = "" Then
MsgBox "用户名不能为空!", vbCritical, Me.Caption
Me.txtUser.SetFocus
GoTo ExitSub
ElseIf Me.txtPwd = "" Then
MsgBox "请填写密码!", vbCritical, Me.Caption
Me.txtPwd.SetFocus
GoTo ExitSub
End If
Set rstLogin = dbLogin.OpenRecordset("select * from User where Username='" + Trim(Me.txtUser) + "'")
If rstLogin.RecordCount = 0 Then
MsgBox "用户名填写错误!", vbCritical, "错误"
Me.txtUser.SetFocus
Me.txtUser.SelStart = 0
Me.txtUser.SelLength = Len(Me.txtUser)
GoTo ExitSub
End If
If rstLogin.Fields("Pwd") = Trim(Me.txtPwd) Then
'登陆成功
' userName = Trim(Me.txtUser)
Unload Me
Form1.Show
' Call Sound("Login")
Else
MsgBox "密码错误!", vbCritical, "错误"
Me.txtPwd.SetFocus
Me.txtPwd.SelStart = 0
Me.txtPwd.SelLength = Len(Me.txtPwd)
End If
GoTo ExitSub
ExitSub:
intTryTimes = intTryTimes + 1
If intTryTimes = 4 Then
MsgBox "密码错误!", vbInformation, Me.Caption
End
End If
End Sub
Private Sub Form_Load()
Me.Left = Screen.Width / 2 - Me.Width / 2
Me.Top = Screen.Height / 2 - Me.Height / 2
Me.Caption = "登陆"
intTryTimes = 0
Set dbLogin = OpenDatabase(App.Path + "\Data.mdb", False, False, "MS Access;pwd=111")
' Set rstLogin = dbLogin.OpenRecordset("select Username from User")
' If rstLogin.RecordCount <> 0 Then
' Me.txtUser = rstLogin.Fields("Username")
' End If
Show
Me.txtUser.SetFocus
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set rstLogin = Nothing
dbLogin.Close
End Sub
Private Sub txtPwd_GotFocus()
Me.txtPwd.SelStart = 0
Me.txtPwd.SelLength = Len(Me.txtPwd)
End Sub
Private Sub txtPwd_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Call cmdLoginEnter_Click
End If
End Sub
Private Sub txtUser_GotFocus()
Me.txtUser.SelStart = 0
Me.txtUser.SelLength = Len(Me.txtUser)
End Sub
Private Sub txtUser_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Call cmdLoginEnter_Click
End If
End Sub
--------------
给分吧!
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
AiPPT
2024-09-19 广告
2024-09-19 广告
随着AI技术的飞速发展,如今市面上涌现了许多实用易操作的AI生成工具1、简介:AiPPT: 这款AI工具智能理解用户输入的主题,提供“AI智能生成”和“导入本地大纲”的选项,生成的PPT内容丰富多样,可自由编辑和添加元素,图表类型包括柱状图...
点击进入详情页
本回答由AiPPT提供
展开全部
是要这种效果吗?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询