Click here to Skip to main content
15,912,493 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have a vb.net with database access application.
I have multiple column e.g. A1, A2, A3
To search a particlular value in IDtxt in A1 column I am using this code.

Private Sub btnSearchID_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearchID.Click
        Me.VerifiedHPReportBindingSource.Filter = "[A1] = '" & Me.IDtxt.Text & "'"
    End Sub


How can I search particular value in A1,A2,A3 column?

I am using databindingsource to retrive the value.

What I have tried:

I tried following codes but not working

Private Sub btnSearchID_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearchID.Click
        Me.VerifiedHPReportBindingSource.Filter = "[A1] = '" & Me.IDtxt.Text & "'"
        Me.VerifiedHPReportBindingSource.Filter = "[A2] = '" & Me.IDtxt.Text & "'"
        Me.VerifiedHPReportBindingSource.Filter = "[A3] = '" & Me.IDtxt.Text & "'"
    End Sub
Posted
Updated 13-Feb-17 10:13am

1 solution

You'll need to combine the filter conditions into a single string:
VB.NET
Me.VerifiedHPReportBindingSource.Filter = String.Format("[A1] = '{0}' Or [A2] = '{0}' Or [A3] = '{0}'", Me.IDtxt.Text)
 
Share this answer
 
Comments
Karthik_Mahalingam 14-Feb-17 0:18am    
5
Member 10804809 14-Feb-17 7:04am    
Thanks, It worked fine.
One modification-is it possible to highlight the searched value in respective Textbox as I m using 60 Textbox in one form.
Richard Deeming 14-Feb-17 7:58am    
So you just want to change the background colour of the textbox you're using in the search?

Just create a method to reset the background colour of all 60 textboxes. In each search method, call that method, then change the background colour of the relevant textbox to something else.
Member 10804809 14-Feb-17 10:35am    
I have developed this code but how can apply to all 60 textbox?
If A1TextBox.Text = IDtxt.Text Then
A1TextBox.BackColor = Color.Red
Else : A1TextBox.BackColor = Color.White

End If
Richard Deeming 14-Feb-17 10:53am    
Something like this:
Private Sub HighlightMatch(ByVal searchValue As String)
    A1TextBox.BackColor = If(A1TextBox.Text = searchValue, Color.Red, Color.White)
    A2TextBox.BackColor = If(A2TextBox.Text = searchValue, Color.Red, Color.White)
    A3TextBox.BackColor = If(A3TextBox.Text = searchValue, Color.Red, Color.White)
End Sub

Private Sub btnSearchID_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearchID.Click
    Me.VerifiedHPReportBindingSource.Filter = String.Format("[A1] = '{0}' Or [A2] = '{0}' Or [A3] = '{0}'", Me.IDtxt.Text)
    HighlightMatch(Me.IDtxt.Text)
End Sub

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900