Solved

VB.net Filter a column by a certain value

Posted on 2013-01-14
2
289 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
2 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
Comment Utility
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
Comment Utility
Thanks very much
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now