0

In ASP.NET I have SqlDataSource, I pass into that ProductName as parameter and get ProductId from Select method.

Problem is when i pass ProductName containing '&' then Select Method returns nothing.

I tried replace '&' with '\&' like name=name.Replace("&",@"\&");
but nothing changes.

How can I handle that problem?

el vis
  • 1,302
  • 2
  • 16
  • 32
  • 1
    & is not a special character in t-sql, have you printed out the values and verified its not something like *&* ? – Alex K. Aug 02 '12 at 10:06
  • You're right about & is not a special character - sql query in Managment Studio worked. So it's not a problem here. Yeah I printed that and it is normal string with single &. But still no results. – el vis Aug 02 '12 at 10:14
  • If in your asp.net code you hard-code a valid value `name = "Beer & Pie";` does it work? – Alex K. Aug 02 '12 at 10:19
  • Then the string from the query/form data must be weird, when you looked for & did you do it in the debugger? if you look at it written back in the browser you need to view its source – Alex K. Aug 02 '12 at 10:25
  • I have looked at it assigned to some Label.Text; I'll try do it while debugging (now i have some problems with launching that ;) ). I can only add that i get that value from Gridview like : `row.Cells[1].Text;` – el vis Aug 02 '12 at 10:43
  • Hi, @Alex K. I managed to debbug it and there is `name="ProductName1 & new"` , do you know any solution ? – el vis Aug 03 '12 at 09:48
  • Try http://stackoverflow.com/questions/122641/how-can-i-decode-html-characters-in-c – Alex K. Aug 03 '12 at 09:50
  • Thank you very much! Thats a solution! – el vis Aug 03 '12 at 09:52

0 Answers0