金普新区新任领导班子:谁有VB与SQL数据库相连的一个登入窗口啊,只要代码就可以

来源:百度文库 编辑:查人人中国名人网 时间:2024/05/06 18:51:56

VERSION 5.00
Begin VB.Form fpas1
BorderStyle = 1 'Fixed Single
Caption = "密码"
ClientHeight = 1935
ClientLeft = 45
ClientTop = 330
ClientWidth = 3345
ControlBox = 0 'False
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 1935
ScaleMode = 0 'User
ScaleWidth = 3345
StartUpPosition = 2 '屏幕中心
Begin VB.CommandButton cmdcancel
Caption = "取消"
Height = 375
Left = 1800
TabIndex = 3
Top = 1440
Width = 855
End
Begin VB.CommandButton cmdok
Caption = "确定"
Height = 375
Left = 600
TabIndex = 2
Top = 1440
Width = 855
End
Begin VB.TextBox txtpas
Height = 375
IMEMode = 3 'DISABLE
Left = 360
PasswordChar = "*"
TabIndex = 1
Top = 960
Width = 2535
End
Begin VB.Label Label1
Caption = "请输入密码然后单击确定"
Height = 255
Left = 360
TabIndex = 0
Top = 360
Width = 2055
End
End
Attribute VB_Name = "fpas1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub cmdcancel_Click()
End
End Sub

Private Sub cmdok_Click()
Dim i As Integer
Dim db As Database, rs As Recordset
Dim dbname As String
dbname = App.Path \\取当前路径,数据库一定要和这个窗口在一个文件夹下,不然会报错
If Right(dbname, 1) <> "\" Then dbname = dbname + "\"
dbname = dbname + "cj.mdb" \\cj.mdb:数据库名
Set db = OpenDatabase(dbname)
Set rs = db.OpenRecordset("密码", dbOpenTable) \\密码:数据库表名
rs.MoveFirst
password = rs.Fields("密码") \\密码:字段名
If txtpas.Text = password Then
fpas1.Hide
Else
i = MsgBox("密码错误", 5 + vbExclamation, "输入密码")
If i <> 4 Then
End
Else
txtpas.Text = ""
txtpas.SetFocus
End If
End If
End Sub

这是最简单的,只输入密码就行了,要加用户名的话,应该会加吧