I'm hoping someone has the answer to this problem. I am trying to pass a code behind value (@Artist) to the SqlDataSource control in an aspx file so that the value has a '&' in the string. The code works if there is no & in the value. I've tried escaping the character but get an empty string returned. If I remove the '&' code, it works just fine on values that do not have it.
Here's the code behind:
public partial class Artist : System.Web.UI.Page
{
public string _Artist;
protected void Page_Load(object sender, EventArgs e)
{
string _Artist = Request.QueryString.ToString();
_Artist = Artist
.Substring(7, _Artist.Length - 7)
.Replace("+", " ")
.Replace("&", "\\&");
SqlDataSourceAlbums.SelectParameters.Add("Artist", _Artist);
}
}
Here's the asp:SqlDataSource SELECT query:
SELECT DISTINCT Album FROM dbo.c_mymusic_albums WHERE (Artist = @Artist)
The result is an empty string. How do I fix it so the SELECT query returns value(s)? I'm using C#.
Thanks!