Private Sub Command1_Click()
  Dim mrc As New ADODB.Recordset
  'txtsql = "  select * from oper where 用户名= '" & Trim$(Text1(0).Text) & " ' and 口令= ' " & Trim$(Text1(1).Text) + " ' "
    txtsql = "  select * from oper where 用户名= '1111' and 口令= '1111' "  'Text2.Text = txtsql
   Set mrc = exesql(txtsql)
  If mrc.RecordCount = 0 Then '未找到用户记录
    n = n + 1
    If n < 3 Then
      MsgBox "没有该用户,继续登陆", vbOKOnly + vbExclamation, "信息提示"
           Text1(0).Text = ""
           Text1(1).Text = ""
           Text1(0).SetFocus
    Else
     MsgBox "已登陆失败三次,退出系统", vbOKOnly + vbExclamation, "信息提示"
          mcr.Close
      Unload Me
    End If
 Else '找到合法用户
     userlevel = Trim(mrc.Fields("级别"))
     mrc.Close
     Unload Me
     menu.Show '调用主界面窗体
  End If
End Sub
调试时老说没有用户什么什么的小菜鸟 有点郁闷啊

解决方案 »

  1.   

    exesql()函数的代码呢?看这个是否有问题
      

  2.   

    Public Function exesql(ByVal sql As String) As ADODB.Recordset ' 用于执行SELECT语句
    sql = Trim$(sql)
    Set conn = New ADODB.Connection
    Set rst = New ADODB.Recordset
    conn.ConnectionString = "dsn=KS;uid=MICROSOF-45B405;pwd=;"
    conn.Open
    Set rst.ActiveConnection = conn
    rst.LockType = adLockOptimistic
    rst.CursorType = adOpenKeyset
    rst.Open sql
    Set exesql = rst
    Set exesql = Nothing '释放记录
    Set conn = Nothing '释放连接End Function
    第一句是不是啊 
      

  3.   

    Public Function exesql(ByVal sql As String) As ADODB.Recordset ' 用于执行SELECT语句 
    sql = Trim$(sql) 
    Set conn = New ADODB.Connection 
    Set rst = New ADODB.Recordset 
    conn.ConnectionString = "dsn=KS;uid=MICROSOF-45B405;pwd=;" 
    conn.Open 
    Set rst.ActiveConnection = conn 
    rst.LockType = adLockOptimistic 
    rst.CursorType = adOpenKeyset 
    rst.Open sql 
    Set exesql = rst 
    Set rst = Nothing '释放记录 
    Set conn = Nothing '释放连接 End Function 
      

  4.   

    还是没用的捏。。大虾帮帮忙的啊 。。小弟做课程设计都急死了饿
    Private Sub Command1_Click() 
      Dim mrc As New ADODB.Recordset 
      'txtsql = "  select * from oper where 用户名= '" & Trim$(Text1(0).Text) & " ' and 口令= ' " & Trim$(Text1(1).Text) + " ' " 
        txtsql = "  select * from oper where 用户名= '1111' and 口令= '1111' "   'Text2.Text = txtsql 
      Set mrc = exesql(txtsql) 
      If mrc.RecordCount = 0 Then '未找到用户记录 
        n = n + 1 
        If n < 3 Then 
          MsgBox "没有该用户,继续登陆", vbOKOnly + vbExclamation, "信息提示" 
              Text1(0).Text = "" 
              Text1(1).Text = "" 
              Text1(0).SetFocus 
        Else 
        MsgBox "已登陆失败三次,退出系统", vbOKOnly + vbExclamation, "信息提示" 
              mcr.Close 
          Unload Me 
        End If 
    Else '找到合法用户 
        userlevel = Trim(mrc.Fields("级别")) 
        mrc.Close 还显示这里有问题的啊
        Unload Me 
        menu.Show '调用主界面窗体 
      End If 
    End Sub 
      

  5.   

    给你一个参考下思路吧
    Dim micount As Integer
    Private Sub Command1_Click()
        Dim txtSql As String
        Dim mrc As ADODB.Recordset
        Dim msgtext As String
        UserName = "" '这是个全局变量
        
        If Trim(txtUserName.Text = "") Then
            MsgBox "没有这个用户,请重新输入用户名!", vbOKOnly + vbExclamation, "警告"
            txtUserName.SetFocus
        Else
            txtSql = "select * from financer where 用户名='" & txtUserName.Text & "'"
            Set mrc = ExecuteSQL(txtSql, msgtext) '这个ExecuteSQL也是个自定义的函数
            If mrc.EOF = True Then
                MsgBox "没有这个用户,请重新输入用户名!", vbOKOnly + vbExclamation, "警告"
                txtUserName.SetFocus
            Else
                If Trim(mrc.Fields("密码")) = 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
    End Sub
      

  6.   

    试一试这段代码,根据你提供的原始代码修改的。
    Private Sub Command1_Click() 
      Dim mrc As New ADODB.Recordset 
      'txtsql = "  select * from oper where 用户名= '" & Trim$(Text1(0).Text) & " ' and 口令= ' " & Trim$(Text1(1).Text) + " ' " 
        txtsql = "  select * from oper where 用户名= '1111' and 口令= '1111' "   'Text2.Text = txtsql 
      Set mrc = exesql(txtsql) 
      If mrc.eof or mrc.bof Then '未找到用户记录 
        n = n + 1 
        If n < 3 Then 
          MsgBox "没有该用户,继续登陆", vbOKOnly + vbExclamation, "信息提示" 
              Text1(0).Text = "" 
              Text1(1).Text = "" 
              Text1(0).SetFocus 
        Else 
        MsgBox "已登陆失败三次,退出系统", vbOKOnly + vbExclamation, "信息提示" 
              mcr.Close 
          Unload Me 
        End If 
    Else '找到合法用户 
        userlevel = Trim(mrc.Fields("级别")) 
        mrc.Close 
        Unload Me 
        menu.Show '调用主界面窗体 
      End If 
    End Sub 
      

  7.   

    http://download.csdn.net/source/1498324
    这是我常用的操作数据库的代码,你看看对你有用否。