Click here to Skip to main content
15,749,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

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

it can not encode character *
Updated 20-Sep-11 17:45pm
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    
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

Have you tried just HttpUtility.UrlEncode(...) (no second parameter)
Share this answer
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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900