dbcontrols(泰山__抛砖引玉) 用SQL语句吧,看看Jetsql35.hlp ========================== 其实我也知道可以先 set rs=nothing set rs=rscon.excute("select count(*) from table") 来先查一个记录条数的,可是这样不也是增加了一次数据库访问速度吗?那样的话会降低运行速度的,尤其是table非常大的时候。
rs.movelast DoEvents intrecCount=rs.recordCount DoEvents '可否另外来个文件 来记录 总共的个数 rs.movefirst for intcount=1 to intrecCount cmbname.additem rs.fields("name").value rs.movenext next intCount
老兄,其实你只要这样就可以了,而且一定正确。 rs.movelast rs.movefirst intrecCount=rs.recordCount '我只是给你换了一下行,效果就不一样了,呵呵 for intcount=1 to intrecCount cmbname.additem rs.fields("name").value rs.movenext next intCount这样 回复人: sonicdater(发呆呆) ( ) 信誉:64 2002-4-25 21:03:32 得分:0
如果要优化速度,可以参考下面的方法: Private Declare Function GetInputState Lib "user32" () As Long Public Sub DoEventsEx() If GetInputState() <> 0 Then DoEvents
End Sub Private Sub Command1_Click()
With rs .Open "your rs", adOpenKeyset, adLockOptimistic
Do While Not .EOF cmbname.AddItem .Fields("name").Value
.MoveNext
DoEventsEx Loop
End With
End Sub
只要在打开数据库时加上 db.CursorLocation = adUseClient
With rs_sqb If .State = adStateOpen Then .Close End If .ActiveConnection = adoCN .CursorLocation = adUseClient .CursorType = adOpenStatic .LockType = adLockBatchOptimistic .Source = "SELECT xyesqbbh from XYXSQB " .Open end with
用SQL语句吧,看看Jetsql35.hlp
==========================
其实我也知道可以先
set rs=nothing
set rs=rscon.excute("select count(*) from table")
来先查一个记录条数的,可是这样不也是增加了一次数据库访问速度吗?那样的话会降低运行速度的,尤其是table非常大的时候。
DoEvents
intrecCount=rs.recordCount
DoEvents
'可否另外来个文件 来记录 总共的个数
rs.movefirst
for intcount=1 to intrecCount
cmbname.additem rs.fields("name").value
rs.movenext
next intCount
rs.movelast
rs.movefirst
intrecCount=rs.recordCount '我只是给你换了一下行,效果就不一样了,呵呵
for intcount=1 to intrecCount
cmbname.additem rs.fields("name").value
rs.movenext
next intCount这样
回复人: sonicdater(发呆呆) ( ) 信誉:64 2002-4-25 21:03:32 得分:0
Rs.RecordCount不准确,多半和 游标设置有关.
所说的问题也解决了,这是VB的BUG。
db.CursorLocation = adUseClient
就可以了,不然得到的值总是-1
肯定得
不是vb bug.
施rs.open"",,adopenstatic,adLockOptimistic
不是adOpenDynamic, adLockOptimistic
在Open之前:
recordset.CursorType = adOpenKeyset
recordset.CursorLocation = adUseClient另外,如果你通过command的execute方法打开游标,就会默认是仅向前,上面的设置无效,所以一定要用open打开。
Private Declare Function GetInputState Lib "user32" () As Long
Public Sub DoEventsEx() If GetInputState() <> 0 Then DoEvents
End Sub
Private Sub Command1_Click()
With rs
.Open "your rs", adOpenKeyset, adLockOptimistic
Do While Not .EOF
cmbname.AddItem .Fields("name").Value
.MoveNext
DoEventsEx
Loop
End With
End Sub
db.CursorLocation = adUseClient
If .State = adStateOpen Then
.Close
End If
.ActiveConnection = adoCN
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockBatchOptimistic
.Source = "SELECT xyesqbbh from XYXSQB "
.Open
end with
上borland的网站,在upgrade中的ado部分有这个问题,不过是E文的哦