当成功连接远程数据库时,输进正确的姓名密码时rs.RecordCount 为-1,输进不正确的姓名密码时rs.RecordCount 也为-1错在哪?
      Label4.Caption = "正在登录,请稍候......"
      clientWinsock.Protocol = sckTCPProtocol
      clientWinsock.RemoteHost = "pcjlqpyf4"
      clientWinsock.RemotePort = 4466
      clientWinsock.Connect
      '连接远程数据库
      Dim conn   As New adodb.Connection  '定义数据库的连接
      Set conn = New adodb.Connection
      Dim rs   As New adodb.Recordset
      Set rs = New adodb.Recordset
      conn.ConnectionTimeout = 30
      conn.Open "Provider=SQLOLEDB.1;Persist Security Info=False;DATABASE=user; User ID=sa;pwd=sa;Data Source=pcjlqpyf4"
      rs.Open "select * from userlogin where (( xm='" & Trim(Text1.Text) & " ') and (mm='" & Trim(Text2.Text) & " '))", conn, 3, 3        
      If rs.RecordCount >0 Then
         MsgBox "已登录"
         Unload Me
      Else
         MsgBox "无权登录"
      End If

解决方案 »

  1.   

    .......................
    rs.cursorlocation=aduseclient    --->加這句
    rs.Open "select * from userlogin where (( xm='" & Trim(Text1.Text) & " ') and (mm='" & Trim(Text2.Text) & " '))", conn, 3, 3      
    .......
    ..
      

  2.   

    If Not rs.EOF Then
             MsgBox "已登录"
             Unload Me
          Else
             MsgBox "无权登录"
          End If
      

  3.   

    加conn.CursorLocation = adUseClient
      

  4.   

    在前面加上rs.movelast:rs.movelastIf rs.RecordCount >0 Then
             MsgBox "已登录"
             Unload Me
          Else
             MsgBox "无权登录"
          End If