Click here to Skip to main content
15,889,839 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
when i give whole of fellow name search function is doing well.The problem is when i give partial fellow name it is always displaying "no record". Can anyone please help me out.This is really urgent.My coding is in C#(winforms)
Posted
Updated 1-Jul-15 20:36pm
v2

1 solution

The code you provided is prone to SQL injection. Always use Parameters.Add() to add parameters/dynamic values to your SqlCommand object. However, I think you helper(MySqlHelper) does not support that. You can change your helper if you want your code to be more secure.

Coming back to the problem you are facing:
You are not using wild card characters(%) in your search query. Replace the SQLCommand query with the one given below:

C#
DataTable dtSearch = VMR.MySqlHelper.GetDataTable("select * from table_name where S_ID = '" + txtSearch.Text + "' OR Fellow_name like '%" + txtSearch1.Text + "%'");
 
Share this answer
 
Comments
Member 11793580 30-Jun-15 1:39am    
Thanks for the response.
I replaced the query with the one u have given but it is not displaying names when i give part of name.
I have used parameters in insert code.
Abhipal Singh 30-Jun-15 2:36am    
Can you provide sample data from your database and also, the input you are giving in the textbox.
Abhipal Singh 30-Jun-15 2:52am    
select * from table_name where S_ID = '" + txtSearch.Text + "' OR Fellow_name like '%A-Z%';

In the above query you have hardcoded A-Z which is incorrect. You need to replace it with txtSearch1.Text as suggested in the solution.

To test the query replace the 'A-Z' with 'da' as given below:
select * from table_name where S_ID = '" + txtSearch.Text + "' OR Fellow_name like '%da%';
Member 11793580 30-Jun-15 2:55am    
But if i mention %da% it will give only those two names.I want search criteria on all of the names in the database i.e., names starting from A till Z.
Abhipal Singh 30-Jun-15 3:02am    
All the names will start from albhabets I believe. That means it is not a filter at all.

The query in Solution will handle this situation. You can keep your textbox as empty and click on search and you will get all the names.

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