简体   繁体   中英

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(); Note that I get this error only when _ImageB is null . ImageB is stored as a Image Data type in the SQL Server table.

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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