Private Sub Command1_Click()
Dim intRespond As Integer
Dim strSql, strSql1 As String
Dim i As Integer
Dim rs As ADODB.Recordset
If Trim(Text2.Text) <> Trim(Text3.Text) Then
intRespond = MsgBox("您的密码输入不一致", 5, "警告")
If intRespond = vbRetry Then
Text2.Text = ""
Text3.Text = ""
Text2.SetFocus
Exit Sub
End If
End If
conn.Open PstrConn
AdoData.ConnectionString = PstrConn
'Debug.Print rs.Source
'strSql = "select * from [user_table] where [用户名] Like & '" & Trim(Text1.Text) & "'"
strSql = "select * from [user_table] where [用户名] = '" & Trim(Text1.Text) & "'"
Set rs = New ADODB.Recordset
Set rs = conn.Execute(strSql)
Debug.Print rs.RecordCount
End sub
各位大侠,为什么我从ACCESS里执行select语句的时候,返回5条记录,但是我用rs.RecordCount则打印的值却为-1,这是为什么,我如果不用这个方法,我怎么可以知道有没有满足条件的记录呢?谢谢大家,我都弄了一天了,也不知道怎么办,一个人学习VB真的很难,有哪位VB高手愿意加我为朋友,我的MSN为[email protected].大家快来帮帮我好吗?
Dim intRespond As Integer
Dim strSql, strSql1 As String
Dim i As Integer
Dim rs As ADODB.Recordset
If Trim(Text2.Text) <> Trim(Text3.Text) Then
intRespond = MsgBox("您的密码输入不一致", 5, "警告")
If intRespond = vbRetry Then
Text2.Text = ""
Text3.Text = ""
Text2.SetFocus
Exit Sub
End If
End If
conn.Open PstrConn
AdoData.ConnectionString = PstrConn
'Debug.Print rs.Source
'strSql = "select * from [user_table] where [用户名] Like & '" & Trim(Text1.Text) & "'"
strSql = "select * from [user_table] where [用户名] = '" & Trim(Text1.Text) & "'"
Set rs = New ADODB.Recordset
Set rs = conn.Execute(strSql)
Debug.Print rs.RecordCount
End sub
各位大侠,为什么我从ACCESS里执行select语句的时候,返回5条记录,但是我用rs.RecordCount则打印的值却为-1,这是为什么,我如果不用这个方法,我怎么可以知道有没有满足条件的记录呢?谢谢大家,我都弄了一天了,也不知道怎么办,一个人学习VB真的很难,有哪位VB高手愿意加我为朋友,我的MSN为[email protected].大家快来帮帮我好吗?
前加一句:rs.CursorLocation =adUseClient
rs.movelast
debug.print rs.recordcount
设置或返回游标引擎的位置。设置和返回值设置或返回可设置为以下某个常量的长整型值。常量 说明
adUseNone 没有使用游标服务。(该常量已过时并且只为了向后兼容才出现)。
adUseClient 使用由本地游标库提供的客户端游标。本地游标引擎通常允许使用的许多功能可能是驱动程序提供的游标无法使用的,因此使用该设置对于那些将要启用的功能是有好处的。adUseClientBatch 与 adUseClient 同义,也支持向后兼容性。
adUseServer 默认值。使用数据提供者或驱动程序提供的游标。这些游标有时非常灵活,对于其他用户对数据源所作的更改具有额外的敏感性。但是,Microsoft Client Cursor Provider(如已断开关联的记录集)的某些功能无法由服务器端游标模拟,通过该设置将无法使用这些功能。
说明该属性允许在可用于提供者的各种游标库中进行选择。通常,可以选择使用客户端游标库或位于服务器上的某个游标库。该属性设置仅对属性已经设置后才建立的连接有影响。更改 CursorLocation 属性不会影响现有的连接。对于 Connection 或关闭的 Recordset 该属性为读/写,而对打开的 Recordset 该属性为只读。Connection.Execute 游标将继承该设置。Recordset 将自动从与之关联的连接中继承该设置。Remote Data Service 用法 当用于客户端 (ADOR) Recordset 或 Connection 对象时,只能将 CursorLocation 属性设置为 adUseClient。
游标类型不能是dynamic,
rs.open strSql,conn,3,1
就可以引用了
要rs.movelast
才能正确返回结果。
Set rs = New ADODB.Recordset
Set rs = conn.Execute(strSql)
debug.print rs.Fields(0).Value
游标定义不正确.
用rs.open conn,sql,3,3试试.
debug.print rs.recordcount
'没有记录
endif
rs.movefrist
debug print rs.recordcount