Click here to Skip to main content
15,917,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
foreach (String entry in GetPageParams().AllKeys)
               {
                   id = Convert.ToInt32(GetPageParams<string>("hdnHistorySave"));
                   if (entry.StartsWith("txtMessage"))
                   {
                       TicketId = entry.ToString().Substring(10);
                       if (id == Convert.ToInt32(TicketId))
                       {
                           objTicket.TicketDetailId = id;
                           objTicket.Message = GetPageParams<string>("txtMessage"+id);

                       }
                   }
               }


Is it possible to do like this?? Because am getting an error ("input string not i correct format") at the id==TicketId Checking .. Please help !
Posted
Comments
Timberbird 14-Jun-12 8:11am    
Check your TicketId value, it cannot be converted to Int32 - put a breakpoint and see its value. Also, entry.ToString() is not needed as entry is already a string

1 solution

You can compare two values of the same type.
If you have a string "12" and a number 2, you can convert the string to a number and then compare it with 2.

If your string is "A12", then you won't be able to convert this to a number.

To avoid an error while converting an alphanumeric string to a number, you can use the TryParse method[^]. This will help you avoid an error while conversion.
 
Share this answer
 
v3
Comments
Arjun Menon U.K 14-Jun-12 8:11am    
Thanks Abinav....I'll try and let you know
NaveenNeo 14-Jun-12 8:15am    
Abhinav S is correct, but why can't you convert int to string and then compare them.Because you are only performing the comparison so i think comparing string will work in your case.
Arjun Menon U.K 14-Jun-12 8:58am    
Worked Fine... there was a comma coming in the string .. my fault... Thanks a lot Abinav and Naveenaka :) Cheers
BillW33 14-Jun-12 9:02am    
Good answer, Abhinav, +5.
Abhinav S 15-Jun-12 2:58am    
Thank you.

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