Anonymous568107

I have got an access table connected to VS 2005, on my form i have a datagridview, a listbox, a textbox and button,

What i want is for the user to type in there query and the datagridview to display the results,

So far heres my code, i am lost i dopn't know how i can get the datagrid to display the query results, plz help

Private Sub btnfind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnfind.Click
Dim sql As String
Dim InventoryDataTable As DataTable = InventoryDataSet.Inventory
sql = "Select * FROM Inventory where Items = " & " '" & searchTxt.Text & "'"
lblSelectString.Text = "Select Command = " + sql

If InventoryDataTable.TableName.ToString() = "System.String" Then


Me.InventoryBindingSource.Filter = sql

End If


sql = Me.InventoryTableAdapter.Fill(Me.InventoryDataSet.Inventory)




End Sub



Re: Visual Basic Language Filtering data in datagridview 2005

PEng1

Have you set the DataGridViews DataSource = InventoryDataSet.Inventory




Re: Visual Basic Language Filtering data in datagridview 2005

Siddarth Chordia

replace this line

sql = "Select * FROM Inventory where Items = " & " '" & searchTxt.Text & "'"

with this one and try if it works out

sql = "Select * FROM Inventory where Items = '" & searchTxt.Text & "' "






Re: Visual Basic Language Filtering data in datagridview 2005

Anonymous

Siddarth Chordia wrote:

replace this line

sql = "Select * FROM Inventory where Items = " & " '" & searchTxt.Text & "'"

with this one and try if it works out

sql = "Select * FROM Inventory where Items = '" & searchTxt.Text & "' "




I found an article on this site and i changed the code to this

Dim InventoryDataTable As DataTable = InventoryDataSet.Inventory


Dim CommandText As String = "Items = " & " '" & searchTxt.Text & "'"
lblSelectString.Text = "Select Command = " + CommandText


Me.InventoryTableAdapter.Fill(Me.InventoryDataSet.Inventory)
Me.InventoryBindingSource.Filter = CommandText

and it is working for me, but thank you for your suggestions.