记录未成功插入不允许从数据类型nvarchar到varbinary(max)的隐式转换.使用CONVERT函数运行此查询.如何解决此错误? [英] Record Not Inserted Successfully Implicit conversion from data type nvarchar to varbinary(max) is not allowed. Use the CONVERT function to run this query.how to solve this error?

查看:788
本文介绍了记录未成功插入不允许从数据类型nvarchar到varbinary(max)的隐式转换.使用CONVERT函数运行此查询.如何解决此错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



谁能解决这个问题.



Can anyone solve this.

Record Not Inserted Successfully Implicit conversion from data type nvarchar to varbinary(max) is not allowed. Use the CONVERT function to run this query.

如何解决此错误?

推荐答案

如果看不到您的代码,则很难确定,但是错误消息非常明显.

您的数据库中有一个已声明为VARBINARY(MAX)的字段,您正在尝试向其中插入值.
要么,您正在尝试通过串联字符串以形成SQL语句来做到这一点:
Without seeing your code, it is difficult to be sure, but the error message is quite explicit.

You have a field in your database that you have declared as VARBINARY(MAX) which you are trying to insert a value to.
Either, you are trying to do this by concatenating strings to form an SQL statement:
string sql = "INSERT INTO myTable (myColumn) VALUES ('" + myDataForColumn + "')";

这是一个非常非常糟糕的主意,因为它使您的数据库容易受到SQL Injection攻击,或者您通过参数化查询但设置了错误的参数类型,或者将字符串传递给SqlCommand.Parameters.AddWithValue来完成此操作字节数组.

Which is a very, very bad idea as it leaves your database open to SQL Injection attack, or you are doing it via a parametrized query but setting the wrong parameter type, or passing a string to SqlCommand.Parameters.AddWithValue instead of an array of bytes.


这篇关于记录未成功插入不允许从数据类型nvarchar到varbinary(max)的隐式转换.使用CONVERT函数运行此查询.如何解决此错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆