简体   繁体   English

操作数类型冲突:nvarchar与Null Image的图像不兼容

[英]Operand type clash: nvarchar is incompatible with image for Null Image

I have the following code: I am getting the following error message: 我有以下代码:我收到以下错误消息:

Operand type clash: nvarchar is incompatible with image 

when the code tries to do: cmd.ExecuteNonQuery(); 当代码尝试执行时: cmd.ExecuteNonQuery(); Note that I get this error only when _ImageB is null . 请注意,只有当_ImageBnull时,我才会收到此错误。 ImageB is stored as a Image Data type in the SQL Server table. ImageB作为图像数据类型存储在SQL Server表中。

if (_ImageB == null)
{
    cmd.Parameters.AddWithValue("@ImageB", DBNull.Value);
}
else
{
    cmd.Parameters.AddWithValue("@ImageB", _ImageB);
}

尝试这个!

cmd.Parameters.Add("@ImageB", SqlDbType.Image).Value = _ImageB == null ? DBNull.Value : _ImageB;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM