Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I get this is Error when I search with employee number instead of something else i.e name or email address Missing operand after 'Employee_ID ' operator? Please assist in providing guideline for the rightway of filtering gridview

private void txtSearch_KeyUp(object sender, KeyEventArgs e)
       {
           string outputInfo = "";
           string[] keyWords = txtSearch.Text.Split(' ');


           try {

               foreach (string word in keyWords)
               {
                   if (outputInfo.Length == 0)
                   {

                       /*Convert Employee number to string if search text is numbers*/
                      outputInfo = "(Firstname LIKE '%" + word + "%' OR LastName LIKE '%" +
                           word + "%' OR Emailaddress LIKE '%" + word + "%' OR GID LIKE '%" + word + "%' OR '" + string.Format("'Employee_ID LIKE '%" + word + "%')");


                   }
                   else
                   {
                       /*Convert Employee number to string if search text is numbers*/
                       outputInfo = "(Firstname LIKE '%" + word + "%' OR LastName LIKE '%" +
                           word + "%' OR Emailaddress LIKE '%" + word + "%' OR GID LIKE '%" + word + "%' OR '" + string.Format("'Employee_ID LIKE '%" + word.ToString() + "%')");


                   }
               }

               //Applies the filter to the DataView
               myView.RowFilter = outputInfo.ToString();

           }catch(Exception ex){
               MessageBox.Show("Result " + ex.Message.ToString() + " Not Found");
           }


       }


What I have tried:

I have tried to convert Employee_ID to string not sure if i am doing it right
outputInfo = "(Firstname LIKE '%" + word + "%' OR LastName LIKE '%" +
                            word + "%' OR Emailaddress LIKE '%" + word + "%' OR GID LIKE '%" + word + "%' OR '" + string.Format("'Employee_ID LIKE '%" + word + "%')");
Posted
Updated 6-Mar-17 23:02pm
v2

OR '" + string.Format("'Employee_ID 

Looks like extra single quotes after OR and before Employee_ID .
 
Share this answer
 
Comments
Member 7763261 3-Mar-17 6:58am    
@Graeme_Grant

Thanks for your response. I have removed the extra quotes now I am getting this error "cannot perform like operation on system.double and system.string". The Employee_ID column I would like to convert to string is in a form of numbers from excel sheet as a db. am I converting the right way? Thanks for further assistance.
Graeme_Grant 3-Mar-17 7:08am    
Yes, LIKE is a string operation. Double values you need to compare: =, !=, <, <=, >=, >.
Arvind Zamakia 3-Mar-17 7:16am    
yes, i think this issue on query string
Member 7763261 7-Mar-17 3:28am    
@Arvind Zamakia and @Graeme_Grant Thanks you so much for your assistance. I have managed to fix my query string. Actually the issue was in my Database since I am using excel. All I did was change Employee_ID to text. All is working fine now. Much thanks for assistance.
/*Convert Employee_ID column to string before using like */
outputInfo = "(Firstname LIKE '%" + word + "%' OR LastName LIKE '%" + word + "%' OR Emailaddress LIKE '%" + word + "%' OR GID LIKE '%" + word + "%' OR "+ string.Format("CONVERT(Employee_ID,'System.String')")+" LIKE '%" + word + "%')";


That works just fine. I hope someone finds it useful. Thanks all in advance for assistance
 
Share this answer
 
v2

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