Dim rs1 As New ADODB.RecordsetPrivate Sub Command1_Click()
  Text1.Text = Replace(Text1.Text, "'", "")
  If Len(Text1.Text) > 10 Then
  MsgBox ("太多了")
  Else
  rs1.Open "select * from TB_USER where strAccountID='" + Text1.Text + "' and  strpasswd='" + Text2.Text + "'", Cnn, adOpenKeyset, adLockOptimistic
  If rs1.RecordCount > 0 Then
  MsgBox ("OK")
  Timer1.Interval = 800
  Timer1.Enabled = True
  Else
  MsgBox ("用户名或者密码错误!")
  End If
  rs1.Close
  End If
End Sub
Private Sub Timer1_Timer()
    rs2.Open "select * from Username where AccountID='tianwei001'", Cnn, adOpenKeyset, adLockOptimistic
    If rs2.RecordCount > 0 Then
    Print ("找到了!")
    Else
    Print ("没有!")
    End If
    rs2.Close
End Sub'为何我的库里名名有数据,却提示找不到呢Public Function Cnn() As String   '返回一个数据库连接
  Cnn = "Provider=sqloledb;Data Source=127.0.0.1;Initial Catalog=tw;User Id=tw;Password=twe;"
End Function

解决方案 »

  1.   

    rs1.Open "select * from TB_USER where strAccountID='" + Text1.Text + "' and  strpasswd='" + Text2 少了"'"
      

  2.   


    这里的没有问题,可能是我少打了,我说的是下面的
    Private Sub Timer1_Timer()
        rs2.Open "select * from Username where AccountID='tianwei001'", Cnn, adOpenKeyset, adLockOptimistic
        If rs2.RecordCount > 0 Then
        Print ("找到了!")
        Else
        Print ("没有!")
        End If
        rs2.Close
    End Sub
    这里一直提示 没有但我库里却是有这条数据。
      

  3.   

    要用recordcount,必须设好cursor。
    用rs2.EOF 试试
      

  4.   

    一样的问题,邪门了,,
    找这个表的数据就能找到。。TB_USER 
      

  5.   

    楼上说的对,COUNT属性有点特殊,或者你可以直接COUNT(*)来看是不是有这条记录
      

  6.   

    换成rs2.EOF 也试过了,还是找不到这条数据
    用COUNT 也是0
    但我库里确实有满足这条件的记录
      

  7.   

    Text2是变量吗?rs1.Open "select * from TB_USER where strAccountID='" + Text1.Text + "' and  strpasswd='" + Text2 
    应该是rs1.Open "select * from TB_USER where strAccountID='" + Text1.Text + "' and  strpasswd='" + Text2.text
      

  8.   


    Private Sub Timer1_Timer() 
        rs2.Open "select * from Username where AccountID='tianwei001'", Cnn, adOpenKeyset, adLockOptimistic 
        If rs2.RecordCount > 0 Then 
        Print ("找到了!") 
        Else 
        Print ("没有!") 
        End If 
        rs2.Close 
    End Sub 是这里出错
      

  9.   

    是否写的和库中不同?比如大小写,空格?
    select * from Username where AccountID='tianwei001'
    这一句在数据库中直接运行看看如果数据后有空格,这样写
    select * from Username where trim(AccountID)='tianwei001'
      

  10.   

    如果使用count函数或rs2.eof 也不能获得正确的结果,建议你把 AccountID='tianwei001' 
    先换成:AccountID like '%tianwei001%' , 如果没有问题,说明该记录中包含了隐藏字符,如:空格、回车什么的;
      

  11.   

    select * from Username where AccountID like '%Data%'
    这样写,也是找不出来我直接在查询管理器却是有数据
      

  12.   

    rs2没设置好吧
    加上这句试试rs2.CursorLocation = adUseClient