powered by simpleCommunicator - 2.0.38     © 2025 Programmizd 02
Форумы / Visual Basic [игнор отключен] [закрыт для гостей] / Как пользоваться командой Find в ADO.Recordset?
2 сообщений из 2, страница 1 из 1
Как пользоваться командой Find в ADO.Recordset?
    #32243507
oops1
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Как пользоваться командой Find в ADO.Recordset?
...
Рейтинг: 0 / 0
Как пользоваться командой Find в ADO.Recordset?
    #32243521
Фотография tpg
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
MSDN:

This example uses the Recordset object's Find method to locate and count the number of business titles in the Pubs database. The example assumes the underlying provider does not support similar functionality.
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
'BeginFindVB

    'To integrate this code
    'replace the data source and initial catalog values
    'in the connection string

Public Sub FindX()

     ' connection and recordset variables
    Dim Cnxn As New ADODB.Connection
    Dim rstTitles As New ADODB.Recordset
    Dim strCnxn As String
    Dim strSQLTitles As String
    
     ' record variables
    Dim mark As Variant
    Dim count As Integer
    
     ' open connection
    Set Cnxn = New ADODB.Connection
    strCnxn = "Provider=sqloledb;Data Source=MyServer;Initial Catalog=Pubs;User Id=sa;Password=; "
    Cnxn.Open strCnxn
       
    ' open recordset with default parameters which are
    ' sufficient to search forward through a Recordset
    Set rstTitles = New ADODB.Recordset
    strSQLTitles = "SELECT title_id FROM titles"
    rstTitles.Open strSQLTitles, Cnxn, adOpenStatic, adLockReadOnly, adCmdText

    count = 0
    rstTitles.Find "title_id LIKE 'BU%'"
    
    Do While Not rstTitles.EOF
        'continue if last find succeeded
       Debug.Print  "Title ID: " ; rstTitles!title_id
        'count the last title found
       count = count + 1
        ' note current position
       mark = rstTitles.Bookmark
       rstTitles.Find  "title_id LIKE 'BU%'" ,  1 , adSearchForward, mark
        ' above code skips current record to avoid finding the same row repeatedly;
        ' last arg (bookmark) is redundant because Find searches from current position
    Loop
    
    Debug.Print  "The number of business titles is "  & count
    
     ' clean up
    rstTitles.Close
    Cnxn.Close
    Set rstTitles = Nothing
    Set Cnxn = Nothing

End Sub
'EndFindVB
...
Рейтинг: 0 / 0
2 сообщений из 2, страница 1 из 1
Форумы / Visual Basic [игнор отключен] [закрыт для гостей] / Как пользоваться командой Find в ADO.Recordset?
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]