I have a text box which allows a user to search for content on our site, here is the c# code to handle was is passed in:
string search = Server.HTMLDecode(userEnteredSearchText);
SqlCommand comm = new SqlCommand("SELECT data FROM database WHERE (Title LIKE @search) "
comm.Parameters.Add(new SqlParameter("search", String.Format("%{0}%", search)));
I’ve never seen this error before:
Cannot convert a char value to money…
but it is going off if the user enters empty spaces. I debugged through it and it seems like what could be causing it is that if search = “”, then the param would be %%? It seems that sometimes if a user enters enough spaces (i.e. search is ” “), then the page does not crash? But I’m not exactly sure what the problem is.
UPDATE:
Not sure exactly what the issue with this is but I fixed it by using a RequiredFieldValidator for the textbox.
@Kevin, Why not check if the user is entering “” ? Then if the user is entering “” give them an error to fix their input before its sent to the database.