|
-
Mar 21st, 2008, 03:47 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] [2005] Find within the string.
I am using the following code for finding the customer name as and when i type in the Combobox.
Code:
Private Sub combobox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.TextChanged
If btnact = "S" Then
CUSTOMERBindingSource.Filter = "name like '" & ComboBox2.Text & "%'"
End If
End Sub
I want to look for the string anywhere within the name. For eg. i want to find 'Jack' from the names of the customers then it should give me the result matching 'Jack' in the 1st name or middle name or last name. However the names of the customer are stored as a single string only. Suppose i have three names in my database containing the word 'Jack' within the string then it should give me the following results
1. Jack Brown
2. Michael Jackson
3. Phill Jack Robinson
What changes do i have to make to my code ?
-
Mar 21st, 2008, 04:19 AM
#2
Hyperactive Member
Re: [2005] Find within the string.
 Originally Posted by LuxCoder
I am using the following code for finding the customer name as and when i type in the Combobox.
Code:
Private Sub combobox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.TextChanged
If btnact = "S" Then
CUSTOMERBindingSource.Filter = "name like '" & ComboBox2.Text & "%'"
End If
End Sub
I want to look for the string anywhere within the name. For eg. i want to find 'Jack' from the names of the customers then it should give me the result matching 'Jack' in the 1st name or middle name or last name. However the names of the customer are stored as a single string only. Suppose i have three names in my database containing the word 'Jack' within the string then it should give me the following results
1. Jack Brown
2. Michael Jackson
3. Phill Jack Robinson
What changes do i have to make to my code ?
just use
if string name.Contains("Jack/whatever") then
//add this name in arraylist
end if
thankx
Koolprasad2003
MCP, MCTS, Microsoft MVP [Asp.Net/IIS]
For more .NET development tips visit .NET Tips
If the post is useful then please  Rate it
-
Mar 21st, 2008, 04:40 AM
#3
Thread Starter
Hyperactive Member
Re: [2005] Find within the string.
i dint get u.... plz explain where should i use it ?
-
Mar 21st, 2008, 05:38 AM
#4
Re: [2005] Find within the string.
You've got a wildcard AFTER your string value, so that's only going to find matches that START with that value. If you want to find matches anywhere in the string then you need a wildcard BEFORE the string too.
-
Mar 21st, 2008, 06:29 AM
#5
Thread Starter
Hyperactive Member
Re: [2005] Find within the string.
U mean like this:
Code:
CUSTOMERBindingSource.Filter = "name like '%" & ComboBox2.Text & "%'"
-
Mar 21st, 2008, 06:36 AM
#6
Thread Starter
Hyperactive Member
Re: [2005] Find within the string.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|