Dim str As String
Dim conn As Connection
Dim rs As RecordsetPrivate Sub cmd_Click()    If rs.State = 1 Then rs.Close
    sql = "select * from nt_user where usercode='" & Trim(usercode.Text) & "' and userpasswd='" & Trim(password.Text) & "'"
    rs.Open sql, conn, adOpenKeyset, adLockOptimistic
    If rs.RecordCount > 0 Then
        mdimain.Show
        Unload main
    Else
        If MsgBox("请输入有效的用户名和密码", vbInformation, "错误") = vbOK Then
        End If
    End If
        
End SubPrivate Sub cmdcancle_Click()
    
    Unload Me
    
End SubPrivate Sub Form_Load()
    
    Set conn = New ADODB.Connection
    str = "Data Source=NTMIT;User ID=sa;Password=ntmitkoei;Initial Catalog=ntsql"
    conn.Provider = "SQLOLEDB"
    conn.ConnectionString = str
    conn.Open
    sql = "Select * from nt_user"
    Set rs = New ADODB.Recordset
    Set rs.ActiveConnection = conn
    rs.CursorLocation = adUseServer
    rs.Open sql, conn, adOpenKeyset, adLockOptimisticEnd SubPrivate Sub password_KeyPress(KeyAscii As Integer)
    
    If KeyAscii = 13 Then
        cmd_Click
    End IfEnd Sub
Private Sub usercode_KeyPress(KeyAscii As Integer)
    
    If rs.State = 1 Then rs.Close
    sql = "select * from nt_user where usercode='" & Trim(usercode.Text) & "'"
    rs.Open sql, conn, adOpenKeyset, adLockOptimistic
    If KeyAscii = 13 Then
        username.Text = rs!username
        password.SetFocus
    End If
        
End Sub