I use this code to select from a table in SQL Server 2008:
sqlcomm.CommandText = "select [objId] from [tablename] where href = @href"
The type of href
in my table is ntext
and I use this code to select:
sqlcomm.Parameters.Add("@href", SqlDbType.NVarChar);
sqlcomm.Parameters["@href"].Value = 'somestring';
IDataReader reader = sqlcomm.ExecuteReader();
But it errors:
The data types ntext and varchar are incompatible in the equal to operator
When I use SqlDbType.NText
it have same error. I can't change type of href
column in my table. When I use like @href
it works, but I couldn't use LIKE
because I want to exact match.
How can I solve my problem?