Click here to Skip to main content
14,358,347 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have a string like
select * from Contacts where lastname='test';


when I'm use urlencode method from php, i get a result
select+%2A+from+Contacts+where+lastname%3D%27test%27%3B



My question is, how to do the same thing with C#, i have tried
HttpUtility.UrlEncode("select * from Contacts where lastname='test';", Encoding.ASCII)

HttpUtility.UrlEncode("select * from Contacts where lastname='test';")

and the result is
select+*+from+Contacts+where+lastname%3d%27test%27%3b

it can not encode character *
Posted
Updated 20-Sep-11 18:45pm
v3
Comments
Prerak Patel 19-Sep-11 23:42pm
   
Why you need to encode query?! If you are passing it via query string, it's a bad idea.
Member 7872856 20-Sep-11 23:54pm
   
yes.
Van Hua 19-Sep-11 23:47pm
   
I don't tried to encode a sql query via query string :) If I want to pass the query string, I can create an property to handle that :)
Van Hua 20-Sep-11 6:31am
   
No one else have an answer :(

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Have you tried just HttpUtility.UrlEncode(...) (no second parameter)
   
Comments
Van Hua 19-Sep-11 23:45pm
   
I also tried that, the second parameter to make sure it use ASCII :) thanks for your quick answer :)
Chris Maunder 19-Sep-11 23:50pm
   
It was a bit of an off-the-cuff answer since we use it that way and I can't recall experiencing the same issue recently. Obviously there's more to the story.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100