VB语言5“用户名”与“密码”实验报告
姓名:叶大塽
学号:15050342035
实验日期:2016.5.26
实验内容:首先创作一个登录页面,然后输入相应的字并对字符大小进行修改,然后建立数据库,在数据库内建立数据表并对表格进行相应的命名,然后编制程序,最后运行输出结果。
实验步骤:
登录-Form-frmlogin StartUpPosition=2,账号-Label TextBox-txtUserID,
密码-Label TextBox-txtpassword,
登录`取消-commandbutton
Cmdlogin-default:true-ENTER
Cmdcancel-cancel:true-ESC
字体:大小:小一
所有控件的tablndex属性:0,1,2,3
Txtuserid-0
Txtpassword-1
Cmdlogin-2
Cmdcandel-3
数据—KU—酷(库)
关系数据
数据表-数据库
列(column)-field(字段,字段语)
行(row)-recorder(记录)
1数据库和表字段如何建立
并向其中添加记录
建库:access:testexample.mdb
建表:userinformation
建字段(2个)
Userid,20,
userpassword,6
添加记录信息:选中表-右键-打开-添加
2可以读取并改写数据表的
第三方程序在哪里
activeX-OLE:
工程-引用-Microsoft activeX Data Objects2.5 library 3VB 如何通过第三方和数据库交互
Connection cn.connectionstriong=“”
Provider=Microsoft。Jet。OLEDN.3.51;
Data source=数据库地址
在connection联通的掉剑侠,可以和数据表进行数据双向传输Recordset
学习一个新的语言[SQL]
Select Update insert into delete
实验程序:Option Explicit
Const MaxLoginTimes As Integer = 3
Private Sub cmdLogin_Click()
Static loginTimes As Integer
loginTimes = loginTimes + 1
If loginTimes < MaxLoginTimes Then
On Error GoTo ppp
Dim Cn As Connection
Dim Rs As Recordset
Dim strSQL As String
Set Cn = New Connection
Set Rs = New Recordset
Cn.ConnectionString = " provider=Microsoft.Jet.OLEDB.3.51;Data Source=C:\Users\jf\Desktop\TestExample.mdb"
Cn.Open
Rs.ActiveConnection = Cn
strSQL = "select UserPassword from UserInformation where UserID= '" & Me.txtUserID.Text & "'"
Rs.Open (strSQL)
If Rs.EOF = True Then
MsgBox txtUserID.Text & "不存在"
Me.txtUserID.SetFocus
Me.txtUserID.SelStart = 0
Me.txtUserID.SelLength = Len(Me.txtUserID.Text)
Else
If Rs.Fields("UserPassword").Value = Me.txtPassword.Text Then
MsgBox "登录成功"
Unload Me
'frmNew.show
Else
MsgBox "密码错误"
End If
End If
ppp:
Cn.Close
Else
MsgBox "亲,您的输入次数超过允许的最大次数", vbCritical, "登录"
End If
End Sub
发现的错误:
出现用户类型未定义,有又从新定义了Connection和Recordset,建立数据库失败,原因是未能正确的建立正确的库,询问其他同学后得以改正。
程序编写有误,缺少相应的语句,并已经改正。
密码后框内字符设置出错,后经过将passwordchar设置成“*”。
忽视引用,后将工程引用中的设置成功