Operand Type Clash

牧云@^-^@ 提交于 2019-12-05 00:49:07

The error is correct, you can't implicitly (or explicitly) cast a VARCHAR(MAX) to sql_variant. If Name is a VARCHAR(MAX) you will need to convert it to a compatible type (like VARCHAR(8000) in order to pass it in as a parameter to sys.fn_sqlvarbasetostr()

see msdn:

sql_variant objects can hold data of any SQL Server data type except text, ntext, image, varchar(max), nvarchar(max), varbinary(max), xml, timestamp, and Microsoft .NET Framework common language runtime (CLR) user-defined types. An instance of sql_variant data also cannot have sql_variant as its underlying base data type.

If you need the functionality of sys.fn_sqlvarbasetostr() and can't down convert your col without losing data, you may need to roll your own version of that function. CLR would be a good bet.

OK, so I had this problem and nothing solved it, until I realized that the string column in DataTable in Code behind should be limited in length, and it solved the problem. No casting or Converting helped.

dt.Columns.Add("dob", typeof(string)).MaxLength = 200;

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!