Search DataGridView Using TextBox in VB.Net and MySQL Database

4
8177

Search DataGridView Using TextBox in VB.Net and MySQL Database

This tutorial is all about How to Search Data in the DataGridView Using a TextBox in VB.Net and MySQL Database. In this tutorial, I will show you how to search for records in VB.Net and MySQL Database.

The list of records in the database will be displayed on the Datagridview and it will show you how easy it is to search a record using a TextBox.

Lets’ begin:

How to search datagridview using textbox vb.net

Step 1: Download the database of this project is located in this link here. (Follow the instructions for creating a database.)

Step 2: After creating a database, open the Visual Basic and create a new Windows Form Application. After that, set the Form just like this.
searchdataform
Step 3: After setting up the Form, double click it and do this code for setting up the connection of MySQL Database to Visual Basic and declare all the classes that are needed above the Form1_Load

 

Note: add mysql.data.dll like your reference to make MySQL work. Follow here the Complete Guide on How to add mysql.data.dll to your vb.net application.

Step 4: Go to Form1_Load and do the following codes for retrieving the record in the database.

Step 5: Go back to the Form Design, double click the “Search” Button and do this code for searching the records in the database.

Download the Code

Download the complete Source Code and run it on your computer searchdatadatagridview

Inquiries

If you have any questions or suggestions about this tutorial on how to Search data in the DataGridView Using TextBox in VB.Net and MySQL Database. Please leave a comment below.

If you want to learn how to master the VB.Net with MySQL Database in 30 minutes, watch and follow the video here.

Readers might read also:

4 COMMENTS

  1. HI…! I NEED HELP FROM THE EXPERT.. THIS IS MY CODE THIS CODE IS DISPLAYING DATA FROM MY TABLE TO MY DATAGRID VIEW.. I WANT TO ADD A INNER JOIN TO MY CODE TO SELECT SOME DATA THERE AND THAT DATA WOULD BE DISPLAY ON MY TXTBOX NOT ON MY DATAGRID.. EXAMBLE DATA IS THE THE NAME OF THE PERSON AND THE OTHER DATA WOULD BE DISPLAY ON MY DATAGRID VIEW.. TNXX…

    ‘SEARCH BUTTON

    Dim CMD As New OleDbCommand
    Dim cnn As New OleDbConnection
    Dim dt As New DataTable
    Dim da As New OleDbDataAdapter
    Dim DS As New DataSet

    cnn.ConnectionString = “provider=Microsoft.SQLSERVER.CE.oleDb.3.5;Data Source=C:\Users\user\Documents\2017TAXPAYERRECORD.sdf;”
    cnn.Open()

    Text = cnn.State.ToString
    Dim str As String
    str = “SELECT TIN,QUARTER,FORMTYPE,RETURNPERIOD,TOTALAMOUNT,DATEOFPAYMENT FROM TAXPAYMENT WHERE TIN='” & STIN.Text & “‘AND RETURNPERIOD='” & SRPERIOD.Text & “‘AND FORMTYPE='” & SFOARMTYPE.Text & “‘”
    da = New OleDbDataAdapter(str, cnn)
    da.Fill(dt)
    DataGridView1.DataSource = dt

    Me.TAXPAYMENTTableAdapter1.Fill(Me.NEWPAYMENTLIST.TAXPAYMENT)

    End Sub

  2. HI NEED HELP FOR THE EXPERT.. THIS MY CODE FOR SEACHING RECORD.. I WANT THE FOLLOWING DATA FIRST NAME, LAST NAME AND MIDDLE NAME OF PERSON WOULD BE DISPLAY ON MY TEXTBOX.. HOW CAN I DO THAT.. PLSSS HELP ME…

    ‘SEARCH BUTTON
    Dim CMD As New OleDbCommand
    Dim cnn As New OleDbConnection
    Dim dt As New DataTable
    Dim da As New OleDbDataAdapter
    Dim DS As New DataSet

    cnn.ConnectionString = “provider=Microsoft.SQLSERVER.CE.oleDb.3.5;Data Source=C:\Users\user\Documents\2017TAXPAYERRECORD.sdf;”
    cnn.Open()

    Text = cnn.State.ToString
    Dim str As String
    str = “SELECT TAXTPERSON.LNAME,TAXTPERSON.FNAME,TAXTPERSON.MNAME,TAXPAYMENT.TIN,TAXPAYMENT.QUARTER,TAXPAYMENT.TAXTYPE,TAXPAYMENT.FORMTYPE,TAXPAYMENT.RETURNPERIOD,TAXPAYMENT.TOTALAMOUNT,TAXPAYMENT.DATEOFPAYMENT FROM TAXPAYMENT INNER JOIN TAXTPERSON ON TAXPAYMENT.TIN = TAXTPERSON.TIN WHERE TAXPAYMENT.TIN='” & STIN.Text & “‘”
    da = New OleDbDataAdapter(str, cnn)
    da.Fill(dt)
    DataGridView1.DataSource = dt

    Me.TAXPAYMENTTableAdapter1.Fill(Me.NEWPAYMENTLIST.TAXPAYMENT)

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.