Solved

Search function in vb.net using an access db

Posted on 2007-04-10
11
178 Views
Last Modified: 2008-01-09
I would like to be able to have a text box where the user enters a name (which is also the field name) and upon clicking the find button, the form will find that record. A find next button will take you to the next record. I am using vb.net as the front end with Access as the back end. How can I go about doing this.
0
Comment
Question by:carlosm06
  • 3
  • 3
  • 2
11 Comments
 
LVL 27

Expert Comment

by:VBRocks
Comment Utility
A very easy way to do this is create a BindingSource and set it's DataSource to whatever list or source you have, then set the BindingSource the DataSource of a BindingNavigator.

First, Add a BindingNavigator to your form, we can call "bn"
Second, create your BindingSource:
Dim bs As New BindingSource()
bs.DataSource = MyList     'Whatever your list is.
bn.BindingSource = bs

If you have a textbox name "Text1" you can filter your bindingsource as follows:
bs.Filter = "ColumnName='" & Text1.Text & "'"

When you want to remove the filter, do as follows:
bs.RemoveFilter()



0
 
LVL 27

Accepted Solution

by:
VBRocks earned 250 total points
Comment Utility
Here is a little example I put together:

First, I created a form and added a BindingNavigator, a textbox to display the data (tbMyColumn), a textbox for search criteria (tbSearch)
Second, I created a DataSet in the designer and added 1 table to it called "MyTable" with 1 column named "MyColumn.

    Private bs As New BindingSource()

    Private Sub Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim i As Integer
        Dim ds As New DataSet1()
        Dim row As DataSet1.MyTableRow

        'Load the dataset with data
        For i = 1 To 10
            row = ds.MyTable.NewMyTableRow()
            row.MyColumn = i

            ds.MyTable.AddMyTableRow(row)

        Next

        'Set the datasource of the BindingSource
        bs.DataSource = ds.MyTable

        'Set the BindingSource for the BindingNavigator
        Me.BindingNavigator1.BindingSource = bs

        'Bind the Text property to your column
        Me.tbMyColumn.DataBindings.Add(New Binding("Text", bs, "MyColumn"))

    End Sub


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        'This is the button that the user clicks to perform the search
        bs.Sort = "MyColumn ASC"
        bs.Filter = "MyColumn='" & Me.tbSearch.Text & "'"

    End Sub

0
 
LVL 18

Expert Comment

by:Priest04
Comment Utility
If you dont want to show only filtered records (like I dont), the other way would be to do a loop through all the records and search for criteria in desired column. If you find a match, you remember the position of the record that matches the criteria. If user preses find next button, you ill loop again through records, but starting from a record that matched the criteria.

Goran
0
 

Author Comment

by:carlosm06
Comment Utility
So if I had the textbox on a seperate form how could I call the record on main form.  Right now I have a small form that users can type in a name and click the search button. When the record is found, I would like to bring up another form with the found record. This is the form used to input data...
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 18

Assisted Solution

by:Priest04
Priest04 earned 250 total points
Comment Utility
1) You show this separate form modally
2) on this separate form have some public variable, to which you will assign value from textbox.
3) When the user clicks search button, close the separate from
4) the code will be returned to main form, so you can read the search value that is stored in a public variable
5) after that, you can use either VBRocks's suggestion, or mine, it all depends what info do you have on this main form, is data shown only for one record, or data are presented in some tabular form (like in datagridview).

Goran
0
 
LVL 27

Expert Comment

by:VBRocks
Comment Utility
Definitely still interested.  I provided a simple and effective, but detailed example.

0
 

Author Comment

by:carlosm06
Comment Utility
Where's the example vbrocks?
0
 
LVL 18

Expert Comment

by:Priest04
Comment Utility
carlosm06, do you find our answers unhelpful?

Goran
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now