vb用户名密码登录程序代码(vb设计用户名和密码登录窗体)

http://www.itjxue.com  2023-03-04 20:12  来源:未知  点击次数: 

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用户怎么登录界面?用户登陆的代码是多少?

vb登陆程序源代码\x0d\x0a\x0d\x0a你可以这样做建一个模块在里面输入下列\x0d\x0aPublic conn As ADODB.Connection\x0d\x0aSub main()\x0d\x0a Set conn = New ADODB.Connection\x0d\x0a conn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;" _\x0d\x0a + "User ID=sa;password=sa;Initial Catalog=您的数据库名;Data Source=127.0.0.1"\x0d\x0a conn.Open\x0d\x0afrom1.Show ’登录界面\x0d\x0aEnd Sub\x0d\x0a\x0d\x0a再在登录界面“确定”下写入如下代码:\x0d\x0aPrivate Sub Command1_Click()\x0d\x0a If id.Text = "" Then\x0d\x0a MsgBox "用户名不能为空!", vbOKOnly + vbInformation, "友情提示"\x0d\x0a id.SetFocus\x0d\x0a Exit Sub\x0d\x0a End If\x0d\x0a If password.Text = "" Then\x0d\x0a MsgBox "密码不能为空!", vbOKOnly + vbInformation, "友情提示"\x0d\x0a password.SetFocus\x0d\x0a Exit Sub\x0d\x0a End If\x0d\x0a\x0d\x0a Dim strSQl As String\x0d\x0a strSQl = "select * from Users where users_name='" Trim$(id.Text) "' and password='" Trim$(password.Text) "' "\x0d\x0a \x0d\x0a Dim str As New ADODB.Recordset\x0d\x0a Set str = New ADODB.Recordset\x0d\x0a str.CursorLocation = adUseClient\x0d\x0a str.Open strSQl, conn, adOpenStatic, adLockReadOnly\x0d\x0a \x0d\x0a With str\x0d\x0a If .State = adStateOpen Then .Close\x0d\x0a .Open strSQl\x0d\x0a If .EOF Then\x0d\x0a Try_times = Try_times + 1\x0d\x0a If Try_times = 3 Then\x0d\x0a MsgBox "您已经三次尝试进入本系统,均不成功,系统将自动关闭", vbOKOnly + vbCritical, "警告"\x0d\x0a Unload Me\x0d\x0a Else\x0d\x0a MsgBox "对不起,用户名不存在或密码错误 !", vbOKOnly + vbQuestion, "警告"\x0d\x0a id.SetFocus\x0d\x0a id.Text = ""\x0d\x0a password.Text = ""\x0d\x0a End If\x0d\x0a Else\x0d\x0a \x0d\x0a Unload Me\x0d\x0a \x0d\x0a Form2.Show ’登录进入的另一个界面\x0d\x0a \x0d\x0a End If\x0d\x0a End With\x0d\x0a\x0d\x0aEnd Sub

VB设置用户和密码登录界面设计及代码 我是新手哦 先谢个

Const

Pwd="Admin"

Const

Usr="Admin"

加入两个文本框和一个按钮控件,2个文本框控件名分别为

UsrTxt

PwdTxt

按钮控件写代码:

if

UsrTxt

=

Usr

and

PwdTxt=Pwd

then

msgbox

"密码正确!",vbinformation,"提示"

else

msgbox

"密码错误!",vbinformation,"提示"

end

if

这是简单的密码登陆,通过更改常量在程序内部规定用户名和密码!其他的自己琢磨下或者给我发邮件

TimeDev@QQ.Com

VB实现密码登录框界面的应用程序代码怎么写?

这个要用数据库Private db As ADODB.Connection

Private rs As ADODB.RecordsetPrivate Sub cmdCancel_Click()

Unload frmlogin

End SubPrivate Sub cmdOK_Click()

Dim i As Integer

For i = 1 To rs.RecordCount

rs.AbsolutePosition = i

If Trim(rs("用户名")) = txtUserName.Text And Trim(rs("密码")) = txtPassword.Text And Trim(rs("权限")) = cmbUserType.Text Then

Select Case Trim(rs("权限"))

Case "管理员"

toper.Show

Unload frmlogin

Exit For

Case "教师"

teacher.Show

Unload frmlogin

Exit For

Case "学生"

student.Show

Unload frmlogin

Exit For

End Select

Else

If i = rs.RecordCount Then

MsgBox "错了,请重试!", , "登陆"

End If

End If

Next

End SubPrivate Sub cmdReset_Click()

txtUserName.Text = ""

txtPassword.Text = ""

cmbUserType.Text = ""

End SubPrivate Sub Form_Load()

Set db = New ADODB.Connection

'connection.open [provider,data source]

'provider:数据库驱动引擎,data source 数据库路径及库名

db.Open "provider= microsoft.jet.oledb.3.51;data source=" App.Path "\ems.mdb"

Set rs = New ADODB.Recordset

rs.Open "login", db, adOpenKeyset, adLockOptimisticEnd Sub

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

(责任编辑:IT教学网)

更多

推荐Discuz!建站文章