Results 1 to 3 of 3

Thread: Searching dataset

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2002
    Posts
    11

    Searching dataset

    Hi! I need to pass search results and reload the form. What's the best way to do it? The code for search routine is below:

    ----------------------------------------------------
    Dim count, i, pos As Integer
    Dim s As String
    s = InputBox("Enter in search criteriar:", "Search")
    If s = "" Then

    Else
    count = 0
    Do Until (count = Me.BindingContext(objBDB, "PDDBdbReport_View").Count)
    If objBDB.PDDBdbReport_View.Rows(count).Item("ProjectNumber") = s Then
    pos = Me.BindingContext(objBDB, "PDDBdbReport_View").Position
    End If
    count = count + 1
    Loop
    If pos > 0 Then
    Me.BindingContext(objBDB, "PDDBdbReport_View").Position = pos

    Else
    MsgBox("Unable to find search.", MsgBoxStyle.OKOnly, "Not found")
    End If
    End If

  2. #2
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    In your code you are just searching for a string and see how many matches there are, and then move the position to the very last one of them. But is that what you mean by search?
    In a simple way you can bind your form to a dataview object and filter that dataview based on the criteria you provide.

    Also: It's not a good practice to leave an empty condition in my opinion. So instead of:
    VB Code:
    1. If s = "" Then
    2.  
    3.         Else
    4.             count = 0
    5.             Do Until (count = Me.BindingContext(objBDB, "PDDBdbReport_View").Count)
    6.                 If objBDB.PDDBdbReport_View.Rows(count).Item("ProjectNumber") = s Then
    7.                     pos = Me.BindingContext(objBDB, "PDDBdbReport_View").Position
    8.                 End If
    9.                 count = count + 1
    10.             Loop
    11.             If pos > 0 Then
    12.                 Me.BindingContext(objBDB, "PDDBdbReport_View").Position = pos
    13.             Else
    14.                 MsgBox("Unable to find search.", MsgBoxStyle.OKOnly, "Not found")
    15.             End If
    16. End If
    You better rephrase it in this way:
    VB Code:
    1. If s <> "" Then
    2.             count = 0
    3.             Do Until (count = Me.BindingContext(objBDB, "PDDBdbReport_View").Count)
    4.                 If objBDB.PDDBdbReport_View.Rows(count).Item("ProjectNumber") = s Then
    5.                     pos = Me.BindingContext(objBDB, "PDDBdbReport_View").Position
    6.                 End If
    7.                 count = count + 1
    8.             Loop
    9.             If pos > 0 Then
    10.                 Me.BindingContext(objBDB, "PDDBdbReport_View").Position = pos
    11.             Else
    12.                 MessageBox.Show("Unable to find search.", "Not found", MessageBoxButtons.OK)
    13.             End If
    14. End If
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2002
    Posts
    11

    Display results?

    Thank you! How to display results on the form?

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