Solved

VB.net Filter a column by a certain value

Posted on 2013-01-14
2
295 Views
Last Modified: 2013-01-14
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
Comment
Question by:Murray Brown
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 38775928
Something like below should work

button_click:

oDataTable_SQL.DefaultView.RowFilter = "SupplierName Like %' & txtSearch.Text & "%'"
Me.DataGridView1.DataSource = oDataTable_SQL.DefaultView
0
 

Author Closing Comment

by:Murray Brown
ID: 38775973
Thanks very much
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

630 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