• We just launched and are currently in beta. Join us as we build and grow the community.

Book Finder Using Quick Search in Visual Basic.Net

ahmedr

Task Automation Guru
A Rep
0
0
0
Rep
0
A Vouches
0
0
0
Vouches
0
Posts
192
Likes
45
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 100 XP
This tutorial is a continuation of “Book Finder Using Visual Basic.Net and MS Access 2007”. At this time, we’re going to learn how to put a Quick search. By using a quick search, we can save more time by specifying the title of a specific book, author, Dewey number and subject.

To start with this tutorial, add a new textbox and name it as “txtquick” and a label, and change the text property to “Quick Search”. Then add two buttons and the first one name it as “btnquick” and change the text property into “Use Quick Search” and the second one name it as “btntxtbox”, and change the text property to “Use Text Box Filter”. And the user interface after designing will look like as shown below.

book2.png


This time, we are now going to add functionality to our program. To do this double click the main form. And the following code below our “con.ConnectionString”.
This code will only disable the “Use Quick Search” button and hide the “txtquick” textbox.
  1. btntxtbox.

    Enabled

    =

    False
  2. txtquick.

    Visible

    =

    False

Then double click the “btnquick” button and add the following code:

The purpose of this code it will on show the “txtquick” and disable other textbox and change the back color into aqua color.

  1. txtquick.

    Visible

    =

    True
  2. btnquick.

    Enabled

    =

    False
  3. btntxtbox.

    Enabled

    =

    True
  4. txttitle.

    Enabled

    =

    False
  5. txtauthor.

    Enabled

    =

    False
  6. txtdewey.

    Enabled

    =

    False
  7. txtsubj.

    Enabled

    =

    False
  8. txttitle.

    BackColor

    =

    Color.

    Aqua
  9. txtauthor.

    BackColor

    =

    Color.

    Aqua
  10. txtdewey.

    BackColor

    =

    Color.

    Aqua
  11. txtsubj.

    BackColor

    =

    Color.

    Aqua

And it looks like as shown below.

book3.png


Then to do the opposite, double click the “Use Text box Filter”, and add the following code:

  1. txtquick.

    Visible

    =

    False
  2. btnquick.

    Enabled

    =

    True
  3. btntxtbox.

    Enabled

    =

    False
  4. txttitle.

    Enabled

    =

    True
  5. txtauthor.

    Enabled

    =

    True
  6. txtdewey.

    Enabled

    =

    True
  7. txtsubj.

    Enabled

    =

    True
  8. txttitle.

    BackColor

    =

    Color.

    Lime
  9. txtauthor.

    BackColor

    =

    Color.

    Lime
  10. txtdewey.

    BackColor

    =

    Color.

    Lime
  11. txtsubj.

    BackColor

    =

    Color.

    Lime

And it looks like as shown below:

book4.png


And finally double click the “txtquick” textbox and add the following code:
When the text is changed, it will automatically populate the datagridview and the user can view a result easily.

  1. Private

    Sub

    txtquick_TextChanged(

    ByVal

    sender As

    System.

    Object

    , ByVal

    e As

    System.

    EventArgs

    )

    Handles

    txtquick.

    TextChanged
  2. 'we set her our SQL statements
  3. sql =

    "Select * from book_profile where title like '%"

    &

    txtquick.

    Text

    &

    "%' or author LIKE '%"

    &

    txtquick.

    Text

    &

    "%'"

  4. dt =

    New

    DataTable
  5. Try
  6. 'open the connection
  7. con.

    Open

    (

    )
  8. 'bind the SQL and the connection through OleDBDataAdaoter and stored to da
  9. da =

    New

    OleDb.

    OleDbDataAdapter

    (

    sql, con)
  10. 'and whatever the value of da will be fill into dt our imaginary data table
  11. da.

    Fill

    (

    dt)
  12. 'get the datasource of datagridview from our data table
  13. dtgresult.

    DataSource

    =

    dt

  14. Catch

    ex As

    Exception
  15. 'will throw an error if something went wrong.
  16. MsgBox

    (

    ex.

    Message

    , MsgBoxStyle.

    Information

    )
  17. End

    Try
  18. 'close connection
  19. con.

    Close

    (

    )
  20. End

    Sub

You can now press “F5” to test your program.


Download
You must upgrade your account or reply in the thread to view the hidden content.
 

452,292

324,186

324,194

Top