Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 304
  • Last Modified:

VB.net Filter a column by a certain value

Hi. I am using the following code to Load a DataGridView with data from an SQL table.
I have a text box (TextBox1) that the user types a Supplier Name  in. What code would I use to Filter the DataGridView to show anything where the SupplierName column is similar in the DataGridView


    Public oAdapter_SQL As SqlDataAdapter
    Public oDataTable_SQL As New DataTable

    Private Sub oLoad
        Try
            'Clear the data table
            Me.DataGridView1.DataSource = Nothing
            Dim sSQL As String
            Dim oConnectionString As String = Globals.ThisAddIn.oRIGHT.lblConnectionString.Text

            sSQL = "Select * From Transactions"

                oDataTable_SQL.Clear()
                Dim connection As New SqlConnection(oConnectionString)
                oAdapter_SQL = New SqlDataAdapter(sSQL, connection)
                oAdapter_SQL.Fill(oDataTable_SQL)
                Me.DataGridView1.DataSource = oDataTable_SQL

        Catch ex As Exception
            MsgBox(ex.Message & " 202")
        End Try
    End Sub
0
Murray Brown
Asked:
Murray Brown
1 Solution
 
CodeCruiserCommented:
Something like below should work

button_click:

oDataTable_SQL.DefaultView.RowFilter = "SupplierName Like %' & txtSearch.Text & "%'"
Me.DataGridView1.DataSource = oDataTable_SQL.DefaultView
0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks very much
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now