vb登陆
程序源代码\x0d\x0a\x0d\x0a你可以这样做建一个模块在里面输入下列\x0d\x0aPublic conn As ADODB.Connection\x0d\x0aSub main()\x0d\x0aSet conn = New ADODB.Connection\x0d\x0a conn.ConnectionString = "Provider=SQLOLEDB.1Persist Security Info=False" _\x0d\x0a + "User ID=sapassword=saInitial Catalog=您的
数据库名Data Source=127.0.0.1"\x0d\x0aconn.Open\x0d\x0afrom1.Show ’登录
界面\x0d\x0aEnd Sub\x0d\x0a\x0d\x0a再在登录界面“确定”下写入如下代码:\x0d\x0aPrivate Sub Command1_Click()\x0d\x0a If id.Text = "" Then\x0d\x0aMsgBox "用户名不能为空!", vbOKOnly + vbInformation, "友情提示"\x0d\x0aid.SetFocus\x0d\x0aExit Sub\x0d\x0aEnd If\x0d\x0aIf password.Text = "" Then\x0d\x0aMsgBox "密码不能为空!", vbOKOnly + vbInformation, "友情提示"\x0d\x0apassword.SetFocus\x0d\x0aExit Sub\x0d\x0aEnd If\x0d\x0a\x0d\x0aDim strSQl As String\x0d\x0astrSQl = "select * from Users where users_name='" &Trim$(id.Text) &"' and password='" &Trim$(password.Text) &"' "\x0d\x0a\x0d\x0aDim str As New ADODB.Recordset\x0d\x0aSet str = New ADODB.Recordset\x0d\x0astr.CursorLocation = adUseClient\x0d\x0astr.Open strSQl, conn, adOpenStatic, adLockReadOnly\x0d\x0a\x0d\x0aWith str\x0d\x0aIf .State = adStateOpen Then .Close\x0d\x0a.Open strSQl\x0d\x0aIf .EOF Then\x0d\x0aTry_times = Try_times + 1\x0d\x0aIf Try_times >= 3 Then\x0d\x0aMsgBox "您已经三次尝试进入本系统,均不成功,系统将自动关闭", vbOKOnly + vbCritical, "警告"\x0d\x0aUnload Me\x0d\x0aElse\x0d\x0aMsgBox "对不起,用户名不存在或密码错误 !", vbOKOnly + vbQuestion, "警告"\x0d\x0aid.SetFocus\x0d\x0aid.Text = ""\x0d\x0apassword.Text = ""\x0d\x0aEnd If\x0d\x0aElse\x0d\x0a\x0d\x0aUnload Me\x0d\x0a\x0d\x0a Form2.Show’登录进入的另一个界面\x0d\x0a\x0d\x0aEnd If\x0d\x0aEnd With\x0d\x0a\x0d\x0aEnd Sub(1)新建数据库并命名为denglu,在该数据库中新建表User1,表包含的列为“ID,username,pwd”。
(2)设计登录界面Frmlogin,以及登录成功后要显示的界面Form2,并连接到数据库,使包含在数据库中的合法用户能成功登录该程序,而不合法用户则无法进入程序。
评论列表(0条)