Results 1 to 9 of 9

Thread: First 10 records?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Pilipinas
    Posts
    441

    First 10 records?

    just asking how i can select the first 10 records in VB?? and the 2nd 10, 3rd 10 and so on...

    "Select * from Table where ???? 1st 10 ???"

    i have no idea?? help me pls?

  2. #2
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: First 10 records?

    To select the Top 10 you could do this...

    VB Code:
    1. Select TOP 10 * from Table where
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Pilipinas
    Posts
    441

    Re: First 10 records?

    how about to the next 10 records??

  4. #4

  5. #5
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: First 10 records?

    The ff. works, perhaps you could use such method also...

    VB Code:
    1. Public Sub X()
    2.     Dim rs1 As ADODB.Recordset
    3.     Set rs1 = New ADODB.Recordset
    4.     With rs1
    5.         .Open "Select TOP 3 ReFNum FROM SubConItinerary WHERE RefNum NOT IN (SELECT TOP 3 RefNum FROM SubConItinerary)", adoConn, adOpenStatic, adLockReadOnly
    6.         Do While Not .EOF
    7.             MsgBox .Fields("RefNum")
    8.             .MoveNext
    9.         Loop
    10.         .Close
    11.     End With
    12.     Set rs1 = Nothing
    13. End Sub
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  6. #6
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: First 10 records?

    I've made a sample which seem to do what you want... It does display the next records but not the first top 3...

    VB Code:
    1. Option Explicit
    2. Private Const intLimit  As Integer = 3
    3.  
    4. Private Sub Sample()
    5.     Dim a As Integer
    6.     Dim adoRecordset As ADODB.Recordset
    7.     For a = 1 To 3
    8.         Set adoRecordset = NextRecordset(a)
    9.         With adoRecordset
    10.             Do While Not .EOF
    11.                 MsgBox .Fields("RefNum")
    12.                 .MoveNext
    13.             Loop
    14.             .Close
    15.         End With
    16.     Next
    17.     Set adoRecordset = Nothing
    18. End Sub
    19.  
    20. 'Sample of getting the next Top 3
    21. Public Function NextRecordset(ByVal i As Integer) As ADODB.Recordset
    22.     Dim rs1 As ADODB.Recordset
    23.     Set rs1 = New ADODB.Recordset
    24.     rs1.Open "Select TOP 3 RefNum FROM SubConItinerary WHERE RefNum NOT IN (SELECT TOP " & (intLimit * i) & " RefNum FROM SubConItinerary)", adoConn, adOpenStatic, adLockReadOnly
    25.     Set NextRecordset = rs1
    26. End Function
    27.  
    28. Private Sub Command1_Click()
    29.     Sample
    30. End Sub

    I tidied it up...

    VB Code:
    1. Option Explicit
    2. Private Const intLimit  As Integer = 3
    3.  
    4. Private Sub Sample()
    5.     Dim a As Integer
    6.     Dim adoRecordset As ADODB.Recordset
    7.     For a = 1 To 3
    8.         NextTop a, adoRecordset
    9.         With adoRecordset
    10.             Do While Not .EOF
    11.                 MsgBox .Fields("RefNum")
    12.                 .MoveNext
    13.             Loop
    14.             .Close
    15.         End With
    16.     Next
    17.     Set adoRecordset = Nothing
    18. End Sub
    19.  
    20. 'Sample of getting the next Top 3
    21. Public Sub NextTop(ByVal i As Integer, ByRef adoRecordset As ADODB.Recordset)
    22.     Set adoRecordset = New ADODB.Recordset
    23.     adoRecordset.Open "Select TOP 3 RefNum FROM SubConItinerary WHERE RefNum NOT IN (SELECT TOP " & (intLimit * i) & " RefNum FROM SubConItinerary)", adoConn, adOpenStatic, adLockReadOnly
    24. End Sub
    25.  
    26. Private Sub Command1_Click()
    27.     Sample
    28. End Sub
    Last edited by dee-u; Nov 25th, 2005 at 12:51 AM.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  7. #7
    Fanatic Member eimroda's Avatar
    Join Date
    Jul 2000
    Location
    Philippines
    Posts
    642

    Re: First 10 records?

    or you can use the PAGE stuff of ADO... its easier...

    i have this in one of my projects... it displays 20 records per page (in a grid)

    VB Code:
    1. Const RecordsPerPage = 20          
    2.  
    3. Sub RefreshGrid(nPage As Integer)
    4. On Error GoTo HELL
    5.     Dim RecsDisplayed As Integer, Qty As Integer
    6.     Dim rsStocks As New ADODB.Recordset
    7.  
    8.     'RS initz here...
    9.    
    10.     'clear grid
    11.     Grid.Rows = 1
    12.    
    13.     With rsStocks
    14.         If .RecordCount > 0 Then
    15.                  
    16.             .AbsolutePage = nPage          'sets where (in what page) it will extract records      
    17.             .PageSize = RecordsPerPage   'sets how many records to be returned      
    18.         End If
    19.  
    20.         Do While Not .EOF And RecsDisplayed < RecordsPerPage
    21.             Grid.AddItem !StkName
    22.  
    23.             RecsDisplayed = RecsDisplayed + 1
    24.             .MoveNext
    25.         Loop
    26.    End With
    27.  
    28.     lblPage = "Page " & nPage & " of " & rsStocks.PageCount
    29.  
    30.     Exit Sub
    31. HELL:
    32.     MsgBox Err.Description, vbCritical
    33. End Sub
    34.  
    35. 'to call it
    36. RefreshGrid 3
    On Error GoTo Hell

    Hell:
    Kill Me


    Food For Thought:

    - Do not judge a book... if you're not a judge!


  8. #8
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: First 10 records?

    Quote Originally Posted by eimroda
    or you can use the PAGE stuff of ADO... its easier...

    i have this in one of my projects... it displays 20 records per page (in a grid)

    VB Code:
    1. Const RecordsPerPage = 20          
    2.  
    3. Sub RefreshGrid(nPage As Integer)
    4. On Error GoTo HELL
    5.     Dim RecsDisplayed As Integer, Qty As Integer
    6.     Dim rsStocks As New ADODB.Recordset
    7.  
    8.     'RS initz here...
    9.    
    10.     'clear grid
    11.     Grid.Rows = 1
    12.    
    13.     With rsStocks
    14.         If .RecordCount > 0 Then
    15.                  
    16.             .AbsolutePage = nPage          'sets where (in what page) it will extract records      
    17.             .PageSize = RecordsPerPage   'sets how many records to be returned      
    18.         End If
    19.  
    20.         Do While Not .EOF And RecsDisplayed < RecordsPerPage
    21.             Grid.AddItem !StkName
    22.  
    23.             RecsDisplayed = RecsDisplayed + 1
    24.             .MoveNext
    25.         Loop
    26.    End With
    27.  
    28.     lblPage = "Page " & nPage & " of " & rsStocks.PageCount
    29.  
    30.     Exit Sub
    31. HELL:
    32.     MsgBox Err.Description, vbCritical
    33. End Sub
    34.  
    35. 'to call it
    36. RefreshGrid 3
    Nice one there eimroda, didn't know about that method...
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  9. #9
    Fanatic Member eimroda's Avatar
    Join Date
    Jul 2000
    Location
    Philippines
    Posts
    642

    Re: First 10 records?

    its like those we see in the web like <previous> 1 2 3 4 <next>, in ASP that PAGE thingy is also used...

    BTW, kabsat napankan idiay www.ilocano.org? adu't agur-uray kaniam idiay a pada a saluyot
    On Error GoTo Hell

    Hell:
    Kill Me


    Food For Thought:

    - Do not judge a book... if you're not a judge!


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width