Public Cn as adodb.connection
sub main
frmLogin.show 1
end sub 在FrmLogin 中有两个文本框分别是用户名(TxtUser)、密码(txtPwd)和登陆(CmdLogin)和退出按钮(CmdExit)
sub Form_Load()
set cn=new adodb.connection
cn.open connstring ' connstring参考Msdn中ado
end sub
sub CmdLogin_click()
dim Rs as new adodb.recordset
if (trim(txtUser.text)<>"") then
Rs.open "select UserName,Pwd From sysUser where UserName='" & trim(txtUser.text) & "' ,cn,3,3
if (not Rs.eof and Rs.bof) then
if txtPwd.text <>rs.("Pwd").value then
Msgbox "Error Pwd" '提示错误
else
FrmMain.show 1 '显示主窗口 end if
else
strsql="Insert into sysUser (UserName,Pwd) values('" & trim(txtUser.text) & "','" & TxtPwd.text & "' "
cn.execute strsql
FrmMain.show 1 '显示主窗口
end if
end if
end sub
这是简单的例子。
解决方案 »
- 弟刚学VB一个学期,学校让做课程设,用VB连access做学生信息管理系统
- vb调用winrar解压缩为什么cpu还会100%呢?
- 如何将rtf文档完整显示在richtextbox中呢?
- 如何在datagrid控件中添加checkbox功能?
- 200分!发现VB版的问题结帖率太低,一些简单的问题大家都争着回答,而有些问题却迟迟没人关注,不利于该版的发展,是否大家能提高一些结
- 急!!如何实现光标离开frame,frame不可见,进入时又可见?
- 小弟由delphi转过来VB,不知道怎样才能最快的上手,用VB来开发
- 请问错在哪里?多谢指点!
- 小case,关于网络密码,请高手指教!
- VB预览AUTOCAD的.DWG文件的问题?
- 我要把access数据库中的所有用户表(不要系统表)全部导入SQL Server7.0中去用vb 怎样实现?
- 新手上路,在线请教!!!高分请教excel中的宏问题
Dim SQLstr As String
Dim msgstring As String
Dim rs As New ADODB.Recordset
If Text1(0).Text = "" Or Text1(1).Text = "" Then
MsgBox "必须输入操作员编号和口令!!!", 48, "错误"
Text1(0).SetFocus
Else
SQLstr = "select * from userID where operatorNo='" & Trim(Text1(0).Text) & "'"
Set rs = ExecuteSQL(SQLstr, msgstring)
If rs.EOF = True Then
MsgBox "操作员编码输入错误!!!", 48, "错误"
Text1(0).Text = ""
Text1(1).Text = ""
Text1(0).SetFocus
Else
If Trim(rs.Fields(2)) = Trim(Text1(1).Text) Then
bh = Text1(0).Text
Load MDIBookMIs
MDIBookMIs.Show
Unload login
rs.Close
Set rs = Nothing
Else
MsgBox "密码输入错误!!!", 48, "错误"
Text1(1).Text = ""
Text1(1).SetFocus
End If
End If
End If
End Sub
Begin VB.Form frmLogin
BorderStyle = 1 'Fixed Single
Caption = "人员登录"
ClientHeight = 1410
ClientLeft = 2865
ClientTop = 3555
ClientWidth = 3570
Icon = "frmLogin.frx":0000
KeyPreview = -1 'True
LinkTopic = "Form1"
LockControls = -1 'True
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 1410
ScaleWidth = 3570
Begin VB.CommandButton Command2
Caption = "取 消"
Height = 345
Left = 2550
TabIndex = 5
Top = 960
Width = 885
End
Begin VB.CommandButton Command1
Caption = "确 定"
Height = 345
Left = 1680
TabIndex = 4
Top = 960
Width = 885
End
Begin VB.TextBox Text1
Alignment = 2 'Center
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 315
IMEMode = 3 'DISABLE
Index = 1
Left = 1890
PasswordChar = "*"
TabIndex = 3
Top = 510
Width = 1515
End
Begin VB.TextBox Text1
Alignment = 2 'Center
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 315
Index = 0
Left = 1890
TabIndex = 1
Top = 120
Width = 1515
End
Begin VB.Image Image1
Height = 630
Left = 90
Picture = "frmLogin.frx":0442
Top = 60
Width = 630
End
Begin VB.Label Label2
AutoSize = -1 'True
Caption = "用户口令:"
Height = 180
Left = 870
TabIndex = 2
Top = 615
Width = 900
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "用户名称:"
Height = 180
Left = 870
TabIndex = 0
Top = 225
Width = 900
End
End
Attribute VB_Name = "frmLogin"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
If Text1(0).Text = "" Then
MsgBox "请输入用户名!", 64, cProgramName
Else
With Rs_Dm_Level
If .State = adStateOpen Then
.Close
End If
.ActiveConnection = adoCN
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.LockType = adLockBatchOptimistic
.Source = "SELECT * FROM Dm_Level order by code"
.Open
End With
With RsUsers
If .State = adStateOpen Then
.Close
End If
.ActiveConnection = adoCN
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.LockType = adLockBatchOptimistic
.Source = "SELECT * FROM Dm_Users WHERE staffname='" & Trim(Text1(0).Text) & "' and password='" & Text1(1).Text & "'"
.Open
If .RecordCount = 1 Then
If .Fields("already") = True Then
MsgBox "此用户已在工作站[" & Trim(.Fields("comuser")) & "]上登录,请重新输入!", 16, cProgramName
.Close
Text1(0).SetFocus
Text1(0).Text = ""
Text1(1).Text = ""
Else
cDeptCode = .Fields("deptcode")
cStaffCode = .Fields("staffcode")
cStaffName = .Fields("staffname")
cUserLevelXYX = .Fields("xyxlevel")
If Not IsNull(.Fields("levelcode")) Then
Rs_Dm_Level.Find "code='" & Trim(.Fields("levelcode")) & "'"
If Not Rs_Dm_Level.EOF Then
cUserLevel = Rs_Dm_Level.Fields("namec")
Else
cUserLevel = ""
End If
Else
cUserLevel = ""
End If
' .Fields("already") = true
.Fields("comuser") = cComputerName
.Fields("logondate") = Now
.Update
.UpdateBatch
.Close
With RsDept
If .State = adStateOpen Then
.Close
End If
.ActiveConnection = adoCN
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.LockType = adLockBatchOptimistic
.Source = "SELECT * FROM Dm_Dept WHERE deptcode='" & cDeptCode & "'"
.Open
If .RecordCount > 0 Then
If Not IsNull(.Fields("contract")) Then
cBDeptCode = .Fields("contract")
Else
cBDeptCode = ""
End If
cDeptName = .Fields("deptname")
End If
.Close
End With
Unload Me
F_Main.Show
End If
Else
MsgBox "您的口令不正确,请重新输入!", 16, cProgramName
Text1(1).SetFocus
Text1(1).SelStart = 0
Text1(1).SelLength = Len(Text1(1).Text)
End If
End With
End If
End SubPrivate Sub Command2_Click()
End
End SubPrivate Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 27 Then
End
End If
End SubPrivate Sub Form_Load()
Dim cForm As String
cForm = FormSet(Me, 5)
End SubPrivate Sub Text1_GotFocus(Index As Integer)
Text1(Index).SelStart = 0
Text1(Index).SelLength = Len(Text1(Index).Text)
End SubPrivate Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
If KeyAscii = 13 And Text1(Index).Text <> "" Then
SendKeys "{tab}"
End If
End SubPrivate Sub Text1_LostFocus(Index As Integer)
Select Case Index
Case 0
With RsUsers
If .State = adStateOpen Then
.Close
End If
.ActiveConnection = adoCN
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.LockType = adLockBatchOptimistic
.Source = "SELECT * FROM DM_USERS WHERE staffcode='" & Trim(Text1(0).Text) & "' or staffname='" & Trim(Text1(0).Text) & "' or bcode='" & Trim(Text1(0).Text) & "'"
.Open
If Not (.BOF And .EOF) Then
Text1(0).Text = Trim(.Fields("staffname")) & ""
Text1(1).Text = ""
Text1(1).SelStart = 0
Text1(1).SelLength = Len(Text1(1).Text)
Else
If Text1(0).Text <> "" Then
MsgBox "错误的用户名!", 16, cProgramName
Text1(0).Text = ""
Text1(0).SetFocus
End If
End If
.Close
End With
End Select
End Sub