3

I have been following the Contoso University tutorial on the ASP.NET website. I am trying to expand my skills and so decided to try adding a third option to the filter. The tutorial provides:

if (!String.IsNullOrEmpty(searchString))
{
    students = students.Where(s => s.LastName.ToUpper().Contains(searchString.ToUpper())
                           || s.FirstMidName.ToUpper().Contains(searchString.ToUpper()));
}

Let's say I've got a third column called Nickname. I tried adding this to the filter by adding an additional || operator:

if (!String.IsNullOrEmpty(searchString))
{
    students = students.Where(s => s.LastName.ToUpper().Contains(searchString.ToUpper())
                           || s.FirstMidName.ToUpper().Contains(searchString.ToUpper())
                           || s.Nickname.ToUpper().Contains(searchString.ToUpper()));
}

When I run with the third option added I get:

[SqlException (0x80131904): Argument data type ntext is invalid for argument 1 of upper function.]

What am I missing here? What do I need to learn next to help me understand more about what's happening here?

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
Mike Rouse
  • 1,278
  • 18
  • 34

2 Answers2

2

I recall having problems with NTEXT columns before when using Entity Framework. To get around this, I now only ever use NVARCHAR(MAX). I am not sure whether that would help in your situation.. whether you are able to change the db type or not... otherwise, there is further info here:

Linq to Entities : using ToLower() on NText fields

Community
  • 1
  • 1
Matt
  • 6,787
  • 11
  • 65
  • 112
1

Try the link below.

http://johnnblade.wordpress.com/2011/01/03/sql-query-replace-error-argument-data-type-ntext-is-invalid-for-argument-1-of-replace-function/

You will have to cast the current text/ntext value as nvarchar(max).

wsclaassen
  • 161
  • 2