1. Open a standard .exe project in Visual Basic. From the Project menu, choose References. Select either the Microsoft Active Data Object 1.5 Library or the Microsoft Active Data Object 2.0 Library.
2. Paste the following code in the form code window:
Option Explicit Dim rs As ADODB.Recordset
Private Sub Form_Load() 'set up rs Set rs = New ADODB.Recordset rs.CursorLocation = adUseServer rs.Open "Select ProductID from products", & _ "Provider=Microsoft.Jet.OLEDB.3.51;" & _ "Data Source=d:/vb5_win95/nwind.mdb", _ adOpenDynamic, adLockUnspecified
Debug.Print rs.RecordCount End Sub
3. Replace the preceding Data Source with a Data Source on your computer. Run the preceding form and note the record count. Change the CursorType to adOpenForwardonly and note the record count.
4. Change the CursorLocation to adUseClient and experiment with the different CursorTypes. In all cases the correct record count returns.
陈晓鸣的意见: 在打开recordset记录集的时候,如果参数3(就是CursorType)为键盘索引或者向前索引时(CursorType参数为0 or 1),为了提高处理速度,recordset纪录是一条一条给你的,而不是一下子都给你的。解决方法是使用动态或静态索引(CursorType参数为2 or 3)