Select to view content in your preferred language

Switching between map services using LIKE and Wild Cards

772
2
06-06-2011 07:46 AM
JoannaLaroussi
Emerging Contributor
Due to size of data I divided my dataset into five feature classes and published five different map services. Now I would like to call specific map service depending from the user input in a text box (InputPED.Text). For example all my fields beginning from 01, and 02 are included in MN map service, when 07 and 08 in BX. So if user types 01002 (or any other number beginning from 01), I would like to call and display MN, but when this is 07001 ??? BX.

At first I tried following expression:
if (InputPED.Text == "01002")
{
   strQueryTaskURL = "url of my MN map service???
}
And it worked fine.

Later I tried to solve the problem in the following way:
//MN
if (InputPED.Text == " '01%' OR '02%'")
{
   strQueryTaskURL = "url of my MN map service???
}
//BX
else if (InputPED.Text == "'07%' OR '08%' ")
{
   strQueryTaskURL = "url of my BX map service???
}
And none of map services url???s was selected. Instead I received an error: ???Invalid Operation Exception was unhandled by user code. URL is not set???.

So I tried use LIKE
                   
if (InputPED.Text "LIKE'01% OR '02%'")
{
   strQueryTaskURL = "url of my MN map service???
}
But it gives me four errors referring to line if (InputPED.Text "LIKE'07% OR '08%'"):
1. ) expected, 2. Invalid expression term ???)???, 3. and 4. ; expected.


I also tried to use Booleans:
string sOptForPED = InputPED.Text.ToString().Trim();
bool bOptForPED = Convert.ToBoolean(sOptForPED);
                 

if (bOptForPED "LIKE '01%'")

{
   strQueryTaskURL = "url of my MN map service???
}
And received errors like above ( ) expected, 2. Invalid expression term ???)???, 3. and 4. ; expected).

I tried to use other wild cards ???LIKE ???01#???, ???LIKE ???01*??? and nothing.

Does anyone have any idea how to solve this problem?
0 Kudos
2 Replies
TerryGiles
Frequent Contributor
try using the String.StartsWith() method or a switch statement on the 1st 2 characters of the value in the textbox


if (InputPED.Text.StartsWith("01") || InputPED.Text.StartsWith("02"))
{
  strQueryTaskURL = "url of my MN map service�?�
}
else if (InputPED.Text.StartsWith("07") || InputPED.Text.StartsWith("08"))
{
  strQueryTaskURL = "url of my BX map service�?�
}


or

            switch (InputPED.Text.Substring(0,2).ToLower())
            {
                case "01":
                case "02":
                    strQueryTaskURL = "url of my MN map service�?�;
                    break;
                case "07":
                case "08":
                    strQueryTaskURL = "url of my BX map service�?�;
                    break;
                default:
                    break;
            }
0 Kudos
JoannaLaroussi
Emerging Contributor
Thanks a lot! I tried the first solution and it works perfectly.
0 Kudos