Click here to Skip to main content
15,892,072 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
i am using winforms(C#) for developing employee details of an organization. I have used groupbox for search criteria which has ID and name. I am able to get the details if i provide whole of first name and search.But my problem is to get all the names displayed based on only part of name given(not whole name).For example, when i give "Da" i textbox all the names starting with Da(david,daniel etc)should be displayed.

May anyone pls help me.
Posted

You can use like operator as demonstrated in solution 1.

If you want suggest append textbox then see below Article...

Autosuggest TextBox from database column in Windows Forms[^]
 
Share this answer
 
Comments
Member 11793580 29-Jun-15 0:28am    
i have done this but always "no record" message is displayed.
sasanka sekhar panda 29-Jun-15 0:29am    
can u please share ur code so that i can find out the mistake..
Member 11793580 29-Jun-15 0:43am    
Load event code

MySqlCommand cmd = new MySqlCommand("SELECT Fellow_name FROM table_name");
MySqlDataReader reader = cmd.ExecuteReader();
AutoCompleteStringCollection MyCollection = new AutoCompleteStringCollection();
while (reader.Read())
{
MyCollection.Add(reader.GetString(0));
}
txtSearch1.AutoCompleteCustomSource = MyCollection;
sasanka sekhar panda 29-Jun-15 1:32am    
AutoCompleteSource CustomSource
AutoCompleteMode SuggestAppend

Did u set all the above properties of txtSearch1.
Member 11793580 29-Jun-15 1:34am    
Yes i have done
Usually the 3rd party WinForm controls handle partial searching for you, if not then you can:

1) If you are using a database, then query by using a % operator on a like : select * from tablename where column like '%da%'
2) If you have in memory collections then use a loop or LINQ and string compare with Contains(): stringvalue.Contains("da");
 
Share this answer
 
Comments
Member 11793580 29-Jun-15 0:35am    
Actually i have to serach based on ID and name.
My previous query was "select * from table_name where S_ID = '" + txtSearch.Text + "' OR Fellow_name = '" + txtSearch1.Text + "'"..which searches using both name and ID.
How do i modify this query?
Mehdi Gholam 29-Jun-15 0:41am    
Try : Fellow_name = '%" + txtSearch1.Text + "%'"

NOTE : your query is subject to sql injection attacks use parameter based queries.
Member 11793580 29-Jun-15 1:01am    
Sorry to say that i am not able to get the solution yet.Thanks for the note,i'll c to it

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