VB和SQL的数据链接做一个登陆系统

设计vb代码,联系SQL数据库中的这两个账号密码,使登陆系统可以运行。求具体编码!

Private conn As New ADODB.Connection
Private Sub LoginProcess()
    Static j As Integer
    Dim rs As New ADODB.Recordset
    
    SQLstr = "select username,password from admin Where username='" & text1.Text & "' and password='" & text2.Text & "'"
    Set rs = conn.Execute(SQLstr)
    If rs.EOF And rs.BOF Then
        j = j + 1
        rs.Close
        Set rs = Nothing
        MsgBox "密码错误"
        If j > 2 Then
            MsgBox "连续错误3次!程序将退出"
            End
        End If
    Else
        rs.Close
        Set rs = Nothing
        MsgBox "登录成功"
'        Form2.Show
        Unload Me
    End If
End Sub
Private Sub Form_Load()
    conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Data.mdb;Mode=ReadWrite|Share Deny None;Persist Security Info=False"
End Sub
Private Sub btLogin_Click()
    Call LoginProcess
End Sub
Private Sub Form_Unload(Cancel As Integer)
        Set conn = Nothing
End Sub

Private Sub text2_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then Call LoginProcess
End Sub

'其中data.mdb是存放账号和密码的数据库文件,本例子采用的是Access数据库。

温馨提示:答案为网友推荐,仅供参考
第1个回答  2017-05-16
可以做的,不知道做完有红。。。包没
相似回答