楼上的朋友,能不能帮我找 BUG啊,谢谢了啊!

解决方案 »

  1.   

    Private Sub cmdOK_Click()
        Dim txtSQL As String
        Dim mrc As New ADODB.Recordset
        Dim cnn As New ADODB.Connection
        Dim MsgText As String    UserName = ""
        If Trim(txtUserName.Text = "") Then
            MsgBox "请输入用户名!", vbOKOnly + vbExclamation, "警告"
            txtUserName.SetFocus
        Else
            txtSQL = "select * from user_Info where user_ID = '" & Trim(txtUserName.Text) & "'"
            '******数据库联接**********
            cnn.Open ""
            mrc.Open txtSQL, cnn
            If mrc.EOF = True Then
                MsgBox "没有这个用户,请重新输入用户名!", vbOKOnly + vbExclamation, "警告"
                txtUserName.SetFocus
            Else
                If Trim(mrc.Fields(1)) = Trim(txtPassword.Text) Then
                    OK = True
                    If mrc.State = 1 Then mrc.Close
                    If cnn.State = 1 Then cnn.Close
                    Set cnn = Nothing
                    Set mrc = Nothing
                    Me.Hide
                    UserName = Trim(txtUserName.Text)
                    Exit Sub
                Else
                    MsgBox "输入密码不正确,请重新输入!", vbOKOnly + vbExclamation, "警告"
                    txtPassword.SetFocus
                    txtPassword.Text = ""
                End If
            End If
        End If
        
        miCount = miCount + 1
        If miCount = 3 Then
            Me.Hide
        End If
        If mrc.State = 1 Then mrc.Close
        If cnn.State = 1 Then cnn.Close
        Set cnn = Nothing
        Set mrc = Nothing
        Exit Sub
    End Sub
      

  2.   

    ExecuteSQL是什么,函数?要想在你的基础上调请找到错误的语句,写明报什么错。
      

  3.   

    全文如下:
    Option Explicit
    Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpbuffer As String, nSize As Long) As Long
    Public OK As Boolean
    '记录确定次数
    Dim miCount As Integer
    Private Sub Form_Load()
        Dim sBuffer As String
        Dim lSize As Long
        sBuffer = Space$(255)
        lSize = Len(sBuffer)
        Call GetUserName(sBuffer, lSize)
        If lSize > 0 Then
            txtUserName.Text = ""
       
        Else
            txtUserName.Text = vbNullString
        End If
            OK = False
        miCount = 0
    End SubPrivate Sub cmdCancel_Click()
        OK = False
        Me.Hide
    End Sub
    Private Sub cmdOK_Click()
        Dim txtSQL As String
        Dim mrc As ADODB.Recordset
        Dim MsgText As String
        'ToDo: create test for correct password
        'check for correct password
        
        UserName = ""
        If Trim(txtUserName.Text = "") Then
            MsgBox "没有这个用户,请重新输入用户名!", vbOKOnly + vbExclamation, "警告"
            txtUserName.SetFocus
        Else
            txtSQL = "select * from user_Info where user_ID = '" & txtUserName.Text & "'"
            Set mrc = ExecuteSQL(txtSQL, MsgText)
            If mrc.EOF = True Then
                MsgBox "没有这个用户,请重新输入用户名!", vbOKOnly + vbExclamation, "警告"
                txtUserName.SetFocus
            Else
                If Trim(mrc.Fields(1)) = Trim(txtPassword.Text) Then
                    OK = True
                    mrc.Close
                    Me.Hide
                    UserName = Trim(txtUserName.Text)
                Else
                    MsgBox "输入密码不正确,请重新输入!", vbOKOnly + vbExclamation, "警告"
                    txtPassword.SetFocus
                    txtPassword.Text = ""
                End If
            End If
        End If
        
        miCount = miCount + 1
        If miCount = 3 Then
            Me.Hide
        End If
        Exit Sub
    End Sub
      

  4.   

    Public LoginSucceeded As BooleanDim rsLogin As ADODB.RecordsetPrivate Sub cmdCancel_Click()
        '设置全局变量为 false
        '不提示失败的登录
    '    LoginSucceeded = False
    '    Me.Hide
        End
    End SubPrivate Sub cmdOK_Click()
        
        Dim sLoginSql As String
        sLoginSql = "SELECT * FROM TU_Manager WHERE s_UserLoginName='" & Trim(txtUserName) & "'"
        
        rsLogin.Open sLoginSql, cn, 1, 3
        If Not rsLogin.RecordCount > 0 Then
            MsgBox "用户名称输入错误或无此用户,请重新输入", vbInformation, "登录"
            txtUserName.SetFocus
            SendKeys "{Home}+{End}"
            rsLogin.Close
            Exit Sub
        End If
        '检查正确的密码
        If txtPassword = Trim(rsLogin("s_UserPWD") & "") Then
            '将代码放在这里传递
            UserInfo(1) = Trim(rsLogin("s_UserLoginName"))
            UserInfo(2) = Trim(rsLogin("s_UserName"))
            UserInfo(3) = Trim(rsLogin("s_UserIdentify"))
            UserInfo(4) = Trim(rsLogin("s_UserLevel"))
            UserInfo(5) = Trim(rsLogin("d_EntryDate"))
            UserInfo(6) = Trim(rsLogin("s_UserPWD"))
            UserInfo(7) = Trim(rsLogin("n_UserID"))
            UserInfo(8) = Trim(rsLogin("s_Power"))
            UserInfo(9) = Trim(rsLogin("d_LoginDate"))
            Dim sSetLoginDateSql As String
            sSetLoginDateSql = "UPDATE TU_Manager SET d_LoginDate=GETDATE() WHERE n_UserID=" & CInt(UserInfo(7)) & ""
            cn.Execute sSetLoginDateSql
            
            '成功到 calling 函数
            '设置全局变量时最容易的
            LoginSucceeded = True
            Me.Hide
            rsLogin.Close
            Set rsLogin = Nothing
            frmMain.Show
        Else
            MsgBox "无效的密码,请重试!", vbExclamation, "登录"
            rsLogin.Close
            txtPassword.SetFocus
            SendKeys "{Home}+{End}"
        End If
    End SubPrivate Sub Form_Load()
        OpenDB
        Set rsLogin = New ADODB.Recordset
    End Sub
      

  5.   

    告诉你吧,楼主你这个错误其实很简单,是因为你执行的这个sql语句被return返回,或者没有返回值!
      

  6.   

    告诉你吧,楼主你这个错误其实很简单,是因为你执行的这个sql语句没有返回值,请用rs.open sqltext去找开就可以了
      

  7.   

    Dim txtSQL As String
        Dim mrc As ADODB.Recordset
        Dim MsgText As String
        Dim cnn as ADODB.Connection    Set cnn = New ADODB.Connection
        Set mrs = New ADODB.Recordset
        
        cnn.Open "连接字符串"    UserName = ""
        If Trim(txtUserName.Text = "") Then
            MsgBox "没有这个用户,请重新输入用户名!", vbOKOnly + vbExclamation, "警告"
            txtUserName.SetFocus
        Else
            txtSQL = "select * from user_Info where user_ID = '" & txtUserName.Text & "'"
            mrc.Open txtSQL, cnn, adOpenDynamic, adLockReadOnly
    .............