Hope you can help me with this.
I'd like to filter my datagridview
by using a certain keyword like a name for example.
I used a data set then bind it to a data source then to my datagridview
for viewing.
When I used the bindingsource.filter
I can't get any result.
Here is my code:
Dim ds As New DataSet
Dim bs As New BindingSource
Dim sql As String = "SELECT TOP 10 * FROM dbo.DimCustomer"
Dim connection As New SqlConnection(sqlconnectionstring)
Dim dataadapter As New SqlDataAdapter(sql, connection)
connection.Open()
ds.Clear()
dataadapter.Fill(ds, "Customer")
connection.Close()
bs.DataSource = ds
dgv1.DataSource = bs
dgv1.DataMember = "Customer"
bs.Filter = "FirstName = 'Jon'"
Thank you guys for the help but I got it working with the following codes below:
Dim sql As String = "select * from HumanResources.vEmployee"
Dim connection As New SqlConnection(sqlconnectionstring)
Dim dataadapter As New SqlDataAdapter(sql, connection)
Dim dsView As New DataView()
Try
connection.Open()
ds.Clear()
dataadapter.Fill(ds, "test")
dsView = ds.Tables(0).DefaultView
bs.DataSource = dsView
dgv1.DataSource = bs
bs.Filter = "FirstName like 'J%'"
Catch ex As Exception
MessageBox.Show("Error while connecting to SQL Server." & ex.Message)
Finally
connection.Close()
End Try