locked
Identifying nvarchar type RRS feed

  • Question

  • Visual Studio Community 2019.  I am trying to execute a select query with 5 columns in a where clause.  4 or the five columns are of type varchar, 1 of type text.  There are no columns of type nvarchar.  Yet, I am getting an exception on the execution: "The data types text and nvarchar are incompatible in the equal to operator".  I am using Parameters.AddWithValue("@Column",objectValue), all data types are matching.

    Is there a way through debugging to find out which column it is identifying as type nvarchar?  

    Sunday, August 18, 2019 1:26 AM

Answers

  • Probably all of your string parameters that are defined with AddWithValue become nvarchar.

    You can specify a different type using this form:

       Parameters.Add(“@Column”, SqlDbType.Text).Value = objectValue.

    However, it seems that text is an obsolete type and it cannot be compared using ‘=’. There are some workarounds (https://www.bing.com/search?q=t-sql+compare+text).

    Maybe you should convert the column to a modern type like nvarchar or nchar.

    Sunday, August 18, 2019 2:46 PM