In my application's search function, I have implemented a search function which executes the following statement against the database.
resultsquery = db.DBMovies.Where(m => (m.Actors.ToLower()).Contains(q.ToLower()))
In the part q.ToLower()
I read the url parameter q
and converts into lowercase and find it in the relevant database column. In my database, the column 'Actors' is of type 'text' rather than varchar. When I run my application, I get an exception called Argument data type text is invalid for argument 1 of lower function
. Is there any way that I can avoid this exception? I prefer a way that I can solve it in a single line.
Thank you.
Just change the datatype of your column in database to NVARCHAR(MAX)
and your code will work like a charm. It's a known issue, if you do some googling. For instance please have a look here.
You can simply convert the column to a VARCHAR - Something like this:
ALTER TABLE DBMovies
ALTER COLUMN Actors VARCHAR(MAX)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With