当前位置:首页 > 代码 > 正文

vb用户登录界面代码(vb设计用户登录界面)

admin 发布:2022-12-19 06:22 142


今天给各位分享vb用户登录界面代码的知识,其中也会对vb设计用户登录界面进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

vb用户登录界面代码

送给你一段现存的登录代码:

Option Explicit

Private Function Selectsql(SQL As String) As ADODB.Recordset '返回ADODB.Recordset对象

Dim ConnStr As String

Dim Conn As ADODB.Connection

Dim rs As ADODB.Recordset

Set rs = New ADODB.Recordset

Set Conn = New ADODB.Connection

'On Error GoTo MyErr:

ConnStr = "Provider=SQLOLEDB.1;Persist Security Info=True;User ID=sa;Password=001234;Initial Catalog=Mydatabase;Data Source=MERRYCHINA" '这是连接SQL数据库的语句

Conn.Open ConnStr

rs.CursorLocation = adUseClient

rs.Open Trim$(SQL), Conn, adOpenDynamic, adLockOptimistic

Set Selectsql = rs

'Exit Function

'MyErr:

'Set rs = Nothing

'Set Conn = Nothing '释放相关的系统资源

'MsgBox Err.Description, vbInformation, "系统提示" '显示出错信息

End Function

Private Sub Form_Load()

Dim SQL As String

Dim rs As ADODB.Recordset

Dim X As Long

On Error GoTo Err_box

SQL = " select * from A用户表 ORDER BY ID"

Set rs = Selectsql(SQL)

If rs.RecordCount 0 Then

rs.MoveFirst

For X = 1 To rs.RecordCount

Combo1.AddItem rs.Fields("姓名").Value

rs.MoveNext

Next X

Combo1.ListIndex = 0

End If

rs.Close

Exit Sub

Err_box:

End Sub

Private Sub Command1_Click()

Dim SQL As String

Dim rs As ADODB.Recordset

If Text1.Text = "" Then

MsgBox "请输入口令!", 64, "提示"

Text1.SetFocus

Exit Sub

End If

If Combo1.Text = "" Then

MsgBox "请选择帐号!", 64, "提示"

Combo1.SetFocus

Exit Sub

End If

SQL = "SELECT * FROM A用户表 WHERE 姓名='" Combo1.Text "' AND 密码='" Text1.Text "' "

Set rs = Selectsql(SQL)

If rs.RecordCount 0 Then

Form1.Show

Unload Me

Else

MsgBox "口令不对,请重新输入!", 64, "提示"

Text1.SetFocus

End If

End Sub

'**********************************************************************

'说明:1) 在工程中引用Microsoft ActiveX Data Objects 2.8 Library ,其它版本也行如:2.0

' 2) 在窗体中加Texe1.text(文本框控件),Combo1.text(组合框控件),Command1(命令按钮)各一个

' 3) 在SQL Server2000中创建数据库"MyDatabase",新建表"A用户表",表中包含"ID,姓名,密码"等字段,然后将以上代码复制,OK搞定

VB的用户登录代码

if text1.text "" and text2.text "" then

if 查找返回值 0 then

if 查找返回值 then

msgbox "登录成功"

form2.show

me.visible = false

' or unload me

else

msgbox "输入密码不正确"

endif

else

msgbox "输入用户名不正确"

Exit sub

endif

else

msgbox "请输入帐号密码"

endif

关于VB设计中一个用户登录界面的代码

我好像看出来一点问题,,,

Adodc1.Recordset.Fields(1).Value对应是应该是数据库里的“密码”这个字段。

而你是用Adodc1.Recordset.Fields(1).Value

Combo1.Text

进行比较,肯定是比不来出什么正确的结果的,它俩天生就不相等。所以程序会继续向下运行。

用户名应该

对应Adodc1.Recordset.Fields(0).Value

怎么用VB设计一个登陆界面?

1.首先添加2个label控件,一个caption为用户名,一个为密码然后分别在2个label控件后面添加一个text控件,

2.将text的text属性设置为空再添加2个button按钮,一个名为登陆,一个名为取消简要代码如下:

private sub text2_change() sswordchar="*"end subprivate sub button1_click()if text1.text="text" and text2.text="123456" then '这里写验证代码...  '通过验证后要干么elsemsgbox("用户名或者密码不正确!")end if end subprivate sub button2_click()endend sub

vb用户怎么登录界面?用户登陆的代码是多少?

vb登陆程序源代码

你可以这样做建一个模块在里面输入下列

Public conn As ADODB.Connection

Sub main()

Set conn = New ADODB.Connection

conn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;" _

+ "User ID=sa;password=sa;Initial Catalog=您的数据库名;Data Source=127.0.0.1"

conn.Open

from1.Show ’登录界面

End Sub

再在登录界面“确定”下写入如下代码:

Private Sub Command1_Click()

If id.Text = "" Then

MsgBox "用户名不能为空!", vbOKOnly + vbInformation, "友情提示"

id.SetFocus

Exit Sub

End If

If password.Text = "" Then

MsgBox "密码不能为空!", vbOKOnly + vbInformation, "友情提示"

password.SetFocus

Exit Sub

End If

Dim strSQl As String

strSQl = "select * from Users where users_name='" Trim$(id.Text) "' and password='" Trim$(password.Text) "' "

Dim str As New ADODB.Recordset

Set str = New ADODB.Recordset

str.CursorLocation = adUseClient

str.Open strSQl, conn, adOpenStatic, adLockReadOnly

With str

If .State = adStateOpen Then .Close

.Open strSQl

If .EOF Then

Try_times = Try_times + 1

If Try_times = 3 Then

MsgBox "您已经三次尝试进入本系统,均不成功,系统将自动关闭", vbOKOnly + vbCritical, "警告"

Unload Me

Else

MsgBox "对不起,用户名不存在或密码错误 !", vbOKOnly + vbQuestion, "警告"

id.SetFocus

id.Text = ""

password.Text = ""

End If

Else

Unload Me

Form2.Show ’登录进入的另一个界面

End If

End With

End Sub

关于vb用户登录界面代码和vb设计用户登录界面的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;

本文地址:http://ahzz.com.cn/post/3754.html


取消回复欢迎 发表评论:

分享到

温馨提示

下载成功了么?或者链接失效了?

联系我们反馈

立即下载