Solved

VB.net Filter a column by a certain value

Posted on 2013-01-14
2
294 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:murbro
[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:murbro
ID: 38775973
Thanks very much
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

739 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