CursorType,LockType问题?!j急

hhfh 2002-02-27 04:14:29
cnnString = "provider=microsoft.jet.oledb.4.0;data source=d:\code.mdb"
cnn1.Open cnnString
rst1.CursorType = adOpenDynamic
rst1.LockType = adLockOptimistic
rst1.Open "select * from 表", cnn1, , , adCmdText
text1.text=rst1.RecordCount

运行时,表里有五个记录,但text1显示为-1!why?
是不是CursorType,LockType设的有问题?!
...全文
162 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
fling_boy 2002-02-27
  • 打赏
  • 举报
回复
需要.
hhfh 2002-02-27
  • 打赏
  • 举报
回复
如我用:
Adodc1.ConnectionString = "provider=microsoft.jet.oledb.4.0;data source= d:\as.mdb"
Adodc1.RecordSource = "select * from saftyqt"
If Adodc1.Recordset.RecordCount > 0 Then
ytjflag = True
End If
那Adodc1.Recordset.RecordCount 还要设置吗?!
forever_chang 2002-02-27
  • 打赏
  • 举报
回复
昨天刚遇到的问题:将cursortype改为adOpenKeyset就好用了
fling_boy 2002-02-27
  • 打赏
  • 举报
回复
recordset.recordcount 需要 cursortype(游标类型)和cursorlocation(游标位置)的支持.
rs.CursorType = adOpenDynamic 为动态游标不支持recordcount.
最好用:rs.CursorLocation = adUseClient(客户端) rs.CursorType = adOpenStatic(静态)
ferrytang 2002-02-27
  • 打赏
  • 举报
回复
rst1.CursorType = adOpenDynamic
这行代码就是说你的数据集的游标类型是动态的
这个时候,你不能通过recordcount来获取纪录的数量了!
只能通过
如果 Recordset 对象支持近似定位或书签(即 Supports (adApproxPosition) 或 Supports (adBookmark) 各自返回 True),不管是否完全填充该值,该值将为 Recordset 中记录的精确数目。如果 Recordset 对象不支持近似定位,该属性可能由于必须对所有记录进行检索和计数以返回精确 RecordCount 值而严重消耗资源。


(盗用泰山的哈哈)
dbcontrols 2002-02-27
  • 打赏
  • 举报
回复
Filter 和 RecordCount 属性范例
该范例使用 Filter 属性打开一个新的 Recordset,它基于适用于已有 Recordset 的指定条件。它使用 RecordCount 属性显示两个 Recordsets 中的记录数。该过程运行时需要 FilterField 函数。

Public Sub FilterX()

Dim rstPublishers As ADODB.Recordset
Dim rstPublishersCountry As ADODB.Recordset
Dim strCnn As String
Dim intPublisherCount As Integer
Dim strCountry As String
Dim strMessage As String

' 使用出版商表中的数据打开记录集。
strCnn = "Provider=sqloledb;" & _
"Data Source=srv;Initial Catalog=pubs;User Id=sa;Password=; "
Set rstPublishers = New ADODB.Recordset
rstPublishers.CursorType = adOpenStatic
rstPublishers.Open "publishers", strCnn, , , adCmdTable

' 充填记录集。
intPublisherCount = rstPublishers.RecordCount

' 让用户输入。
strCountry = Trim(InputBox( _
"Enter a country to filter on:"))

If strCountry <> "" Then
' 打开已筛选的记录集对象。
Set rstPublishersCountry = _
FilterField(rstPublishers, "Country", strCountry)

If rstPublishersCountry.RecordCount = 0 Then
MsgBox "No publishers from that country."
Else
' 打印原始记录集和已筛选记录集对象的记录数。
strMessage = "Orders in original recordset: " & _
vbCr & intPublisherCount & vbCr & _
"Orders in filtered recordset (Country = '" & _
strCountry & "'): " & vbCr & _
rstPublishersCountry.RecordCount
MsgBox strMessage
End If
rstPublishersCountry.Close

End If

End Sub

Public Function FilterField(rstTemp As ADODB.Recordset, _
strField As String, strFilter As String) As ADODB.Recordset

' 在指定的记录集对象上设置筛选操作并打开一个新的记录集对象。
rstTemp.Filter = strField & " = '" & strFilter & "'"
Set FilterField = rstTemp

End Function
注意 当已知要选择的数据时,使用 SQL 语句打开 Recordset 通常更为有效。该范例说明了如何创建唯一的 Recordset 并从特定的国家(地区)获得记录。

Public Sub FilterX2()

Dim rstPublishers As ADODB.Recordset
Dim strCnn As String

' 使用出版商表中的数据打开记录集。
strCnn = "Provider=sqloledb;" & _
"Data Source=srv;Initial Catalog=pubs;User Id=sa;Password=; "
Set rstPublishers = New ADODB.Recordset
rstPublishers.CursorType = adOpenStatic
rstPublishers.Open "SELECT * FROM publishers " & _
"WHERE Country = 'USA'", strCnn, , , adCmdText

' 打印记录集中的当前数据。
rstPublishers.MoveFirst
Do While Not rstPublishers.EOF
Debug.Print rstPublishers!pub_name & ", " & _
rstPublishers!country
rstPublishers.MoveNext
Loop

rstPublishers.Close

End Sub
dbcontrols 2002-02-27
  • 打赏
  • 举报
回复
用 RecordCount 属性可确定 Recordset 对象中记录的数目。ADO 无法确定记录数时该属性返回 –1。读已关闭的 Recordset 上的 RecordCount 属性将产生错误。

如果 Recordset 对象支持近似定位或书签(即 Supports (adApproxPosition) 或 Supports (adBookmark) 各自返回 True),不管是否完全填充该值,该值将为 Recordset 中记录的精确数目。如果 Recordset 对象不支持近似定位,该属性可能由于必须对所有记录进行检索和计数以返回精确 RecordCount 值而严重消耗资源。

7,789

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧