Advertisement

07.22.2008 at 11:27AM PDT, ID: 23586035
[x]
Attachment Details

How do I filter my DataGridView using a ComboBox selection?

Asked by grouchyfd in ADO.Net Class Library, Microsoft Visual Basic.Net

Tags: Microsoft, ViS 2005

I have an ADO.Net app that uses an ODBC connection to a remote database (so I don't need to hardcode in the servername and password). I have one form that uses a DataGridView to show data from a TableView. I need to filter this data using the selected item in a ComboBox. I'm using the SelectedIndexChange method. I can build everything down to the dataset but I cant get the DataGrid view to show any of the selected data. What am I doing wrong?

  Dim Con As New Odbc.OdbcConnection
        Con.ConnectionString = My.Settings.ODBCConnectionString
        Dim Com As New Odbc.OdbcCommand
        Com.Connection = Con
        Com.CommandText = "Select ProductName, CategoryName, Barcode, UnitsInStock, Par " & _
                          "From vProduct " & _
                          "Where ProductName like '" & ComboBox1.SelectedValue & "' and Discontinued = 0 " & _
                          "Order By ProductName"
        Con.Open()
        Dim da As New Odbc.OdbcDataAdapter
        Dim ds As New DataSet

        da.SelectCommand = Com
        da.Fill(ds, "Product")
        VProductDataGridView.DataSource = ds
        VProductDataGridView.DataMember = "Product"

ThanksStart Free Trial
[+][-]07.22.2008 at 11:34AM PDT, ID: 22062219

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.22.2008 at 11:34AM PDT, ID: 22062228

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: ADO.Net Class Library, Microsoft Visual Basic.Net
Tags: Microsoft, ViS 2005
Sign Up Now!
Solution Provided By: VBRocks
Participating Experts: 1
Solution Grade: A
 
 
[+][-]07.22.2008 at 11:36AM PDT, ID: 22062247

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628