Public Function IsExistUser(strusername As String, strpwd As String) As Boolean
Dim cmd As Command
Dim rs As Recordset
Set cmd = New Command
If DataE.conLibrary.State = adStateClosed Then
    DataE.conLibrary.Open
End If
cmd.ActiveConnection = DataE.conLibrary
cmd.CommandText = "select * from usertable where username='" & strusername & " '"
If strpwd <> "" Then
    cmd.CommandText = cmd.CommandText + "and pwd=" & strpwd & " '"
End If
  'MsgBox cmd.CommandText
Set rs = cmd.Execute '这一行提示我“类型不匹配”,请问怎么解决?!
If rs.RecordCount <> 0 Then
    IsExistUser = True
    If blogin Then
        curuserid = rs!userid
        If rs!usertype = manager Then
            badmin = True
        End If
        If curuserid = student Then
            bstudent = True
        End If
    End If
Else
    IsExistUser = False
End If
End Function

解决方案 »

  1.   

    以下摘自MSDN以供参考:如果 CommandType 属性的值等于 adCmdUnknown(默认值),系统的性能将会降低,因为 ADO 必须调用提供者以确定 CommandText 属性是 SQL 语句、还是存储过程或表格名称。如果知道正在使用的命令的类型,可通过设置 CommandType 属性指令 ADO 直接转到相关代码。如果 CommandType 属性与 CommandText 属性中的命令类型不匹配,调用 Execute 方法时将产生错误。
      

  2.   

    Set lvar = New mdlvar
    If Not lvar.IsExistUser(txtusername.Text, txtpassword.Text) Then '在这里调用!!
        DataE.cmdadd 'txtpassword, txtrealname, txtunit, Now, udage, usertype, State
        MsgBox "注册成功!", vbOKOnly + vbInformation, "注意"
        Unload Me
        frmsearch.Show
    Else
        MsgBox "用户已经存在!请重新注册一个新的用户名", vbOKOnly + vbInformation, "注意"
        txtusername.Text = ""
        txtpassword.Text = ""
        txtpwdagain.Text = ""
        txtusername.SetFocus
    End If
    '--------------------------------------------------------
    Public Function IsExistUser(strusername As String, strpwd As String) As Boolean
    Dim cmd As Command
    Dim rs As Recordset
    Set cmd = New Command
    If DataE.conLibrary.State = adStateClosed Then
        DataE.conLibrary.Open
    End If
    cmd.ActiveConnection = DataE.conLibrary
    cmd.CommandText = "select * from usertable where username='" & strusername & " '"
    If strpwd <> "" Then
        cmd.CommandText = cmd.CommandText + "and pwd='" & strpwd & " '"
    End If
      'MsgBox cmd.CommandText
    Set rs = cmd.Execute '现在提示我:[Microsoft][ODBC Microsoft Acess Driver]参数不足,期待是1
    If rs.RecordCount <> 0 Then
        IsExistUser = True
        If blogin Then
            curuserid = rs!userid
            If rs!usertype = manager Then
                badmin = True
            End If
            If curuserid = student Then
                bstudent = True
            End If
        End If
    Else
        IsExistUser = False
    End If
    End Function
    '--------------------------------
    '怎么回事啊,command的 execute方法的参数是可选的啊,可以不谢参数以使用默认的值啊!!!!!!!!!拜托各位了
      

  3.   

    victorycyz(中海)请问大哥qq多少?这个问题很急
      

  4.   

    dim Rs As new adode.recordset