Private Sub Command1_Click()
    Dim con As adodb.Connection
    Dim rs As adodb.Recordset
    Dim sql As String    If Trim(Text1.Text = "") Then
        MsgBox "没有输入用户姓名,请重新输入!", vbOKOnly + vbExclamation, "警告"
        Text1.SetFocus
        Exit Sub
    Else
        Set con = New adodb.Connection
        con.Open "Provider=sqloledb;Data Source=ice_prince;Initial Catalog=zero;User Id=sa;Password=515712;"
        sql = "select * from userinfo where UserID= '" & Trim(Text1.Text) & "' "
        Set rs = New adodb.Recordset
        rs.Open sql, con, adOpenDynamic, adLockOptimistic (这里出错:不能 比较或排序 text\netxt~~~除非使用is null 或 like 运算)
        If rs.EOF And rs.BOF Then
            MsgBox "没有这个用户,请重新输入!", vbOKOnly + vbExclamation, "警告"
            Text1.SetFocus
            rs.Close
            Set rs = Nothing
            con.Close
            Set cn = Nothing
            Exit Sub
        Else
            rs.Close
            Set rs = Nothing
            con.Close
            Set cn = Nothing
            MsgBox "登陆成功~", vbInformation
            '....登陆成功后的其他操作
        End If
    End If
End Sub注以上程序代码是  小马哥 所作本人只是借用!!!!        rs.Open sql, con, adOpenDynamic, adLockOptimistic (这里出错:不能 比较或排序 text\netxt~~~除非使用is null 或 like 运算)
        

解决方案 »

  1.   

    '改成如下试试
    Private Sub Command1_Click()
        Dim con As adodb.Connection
        Dim rs As adodb.Recordset
        Dim sql As String    If Trim(Text1.Text) = "" Then
            MsgBox "没有输入用户姓名,请重新输入!", vbOKOnly + vbExclamation, "警告"
            Text1.SetFocus
            Exit Sub
        Else
            Set con = New adodb.Connection
            con.Open "Provider=sqloledb;Data Source=ice_prince;Initial Catalog=zero;User Id=sa;Password=515712;"
            sql = "select * from userinfo where UserID= '" & Trim(Text1.Text) & "'"
            Set rs = New adodb.Recordset
            rs.Open sql, con
            If rs.EOF And rs.BOF Then
                MsgBox "没有这个用户,请重新输入!", vbOKOnly + vbExclamation, "警告"
                Text1.SetFocus
                rs.Close
                Set rs = Nothing
                con.Close
                Set con = Nothing
                Exit Sub
            Else
                rs.Close
                Set rs = Nothing
                con.Close
                Set con = Nothing
                MsgBox "登陆成功~", vbInformation
                '....登陆成功后的其他操作
            End If
        End If
    End Sub
      

  2.   

    另外,你的text1.text中是否包含数据库不允许的字符?如'或
      

  3.   

    检查一下你的字段类型是否正确。一般你的text1.text包含非法字符了。
      

  4.   

    text1.text中是否有%号等数据库关键字
      

  5.   

    sql = "select * from userinfo where UserID= '" & Trim(Text1.Text) & "' "
    调试时这句会是什么呢?
      

  6.   

    在立即窗口看一下Trim(Text1.Text)的值是什么
      

  7.   

    要从数据库里验证用户那用写好象很麻烦,用这个试试
    Private Sub cmdok_Click()
    Dim strsql As String
    Dim rs As New ADODB.Recordset
    On Error GoTo err
    strsql = "select * from password where usr='" & Trim(txtusrname.Text) & "' and pwd='" & Trim(txtpassword.Text) & "'"
    rs.Open strsql, g_conn,3,1,1
    If rs.EOF Then
    MsgBox "用户名或者密码不正确", , "提示"
    txtusrname.Text = ""
    txtpassword.Text = ""
    txtusrname.SetFocus
    Else
    Unload Me
    MDIForm1.Show
    End If
    Exit Sub
    err:
    MsgBox "错误", , "警告"
    txtusrname.Text = ""
    txtpassword.Text = ""
    txtusrname.SetFocusEnd Sub
    其中g_conn 为数据库连接。我把它做到MODULE里面去了。方面调用。