登錄按鈕的過程的簡單示範

環境:VB6
ADO 2.6或更高



Option   Explicit
Const  conString  =   " Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=dssopt_sms;Data Source=. "
Dim  cn  As  ADODB.Connection


Private   Sub  Command1_Click()

    Static i 
As   Integer   ' 控制登陸的次數
     Dim  Username  As   String
    
Dim  Password  As   String
    
Dim  rs    As  ADODB.Recordset
    
Dim  be    As   Boolean
    
Dim  sql   As   String
    
    i 
=  i  +   1
    Username 
=  txtUser  ‘為了防止注入,要判斷所取的長度、特殊字符替換
    Password 
=  txtPassword
    
    
' 判斷用戶名是否存在
    sql  =   " select * from 登陸 where 用戶名=' "   &  Username  &   " ' "
   
        set 
rs  = new  ADODB.Recordset
     Call  rs.Open(sql, cn,  1 1 )
    be 
=  (rs.EOF  And  rs.BOF)
    rs.Close
    
    
If  be  Then
        
If  i  <   3   Then
            
MsgBox   " 無效的用戶名 " , ,  " 系統登陸 "
            txtUser.SetFocus
            SendKeys 
" {Home}+{end} "
            
Exit   Sub
        
Else
            
MsgBox   " 多次錯誤登陸,再見! " , ,  " 系統登陸 "
            
End
        
End   If
    
End   If
    
    
' 判斷密碼是否正確
    sql  =   " select * from 登陸 where 用戶名=' "   &  Username  &   " ' and 密碼=' "   &  Password  &   " ' "
    
    
Call  rs.Open(sql, cn,  1 1 )
    be 
=  (rs.EOF  And  rs.BOF)
    rs.Close
        set rs = noting
    
    
If   Not  be  Then
        
' frmPic.Show
         ' Denglu_name = Username
         ' Load MDIForm1
        
        
MsgBox   " Login successful! "
        Unload Me
    
Else
        
If  i  <   3   Then
            
MsgBox   " 無效的密碼 " , ,  " 系統登陸 "
            txtPassword.SetFocus
            SendKeys 
" {Home}+{end} "
        
Else
            
MsgBox   " 多次輸入錯誤,請正確輸入! " , ,  " 系統登陸 "
            
End
        
End   If
    
End   If

End Sub

Private   Sub  Form_Load()
    
    
Set  cn  =   New  ADODB.Connection
    cn.Open conString

End Sub

Private Sub Form_Unload(Cancel As Integer)

    If cn.State <> 0 Then cn.Close
    Set cn = Nothing
   
End Sub



 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值