Link to home
Start Free TrialLog in
Avatar of Tech315
Tech315

asked on

C# query

Hello Experts, below I have a query in C# . It returns part of what im looking for. An example is if I type in "york hill" it wont find it because the space is throwing me off. How should I write the query so that it returns the address if it has a space seperating two names.

Thanks


 if (HOME_ADDRESS1 != "")
                {
                   if (count > 0)



              {
                      str = str + " AND HOME_ADDRESS1 LIKE  " + "'%" + HOME_ADDRESS1 + "%' ";
                      count++;
                  }
                   else
               {
                       str = str + " CONTAINS (HOME_ADDRESS1,'" + HOME_ADDRESS1 + ")' ";
                       count++;
                  }
               }
          }
Avatar of p_davis
p_davis

you can string.split on space and which will return an array of strings and you can trim the whitespace from there (just in case there are extra spaces) and then process as needed.
Avatar of Tech315

ASKER

I'm not a programmer by nature, actually a network admin. How would I go about doing what you said?
ASKER CERTIFIED SOLUTION
Avatar of Wim_Bl
Wim_Bl
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tech315

ASKER

Whats the .replace for?
It replaces any spaces in the search string that you pass. If that is not necessary you can let it out of course, but the way the query is set up, it is best to leave it in place. If you omit it and you type in something with a space, that space has to be in the database value as well, but since we strip that out first, it will never be found.
Avatar of Tech315

ASKER

I left the replace and its saying that string does not contain a definition for 'replace' and no extension method. How do I resolve that?
sorry, i think i misunderstood what you wanted earlier... try string.Format

str +=  string.Format(" AND HOME_ADDRESS1 LIKE '%{0}%'", HOME_ADDRESS1);
the {0} is like a place holder
if you wish to use replace method the r needs to be capitalized .Replace()
Avatar of Tech315

ASKER

Thank you kindly for your time and effort!