gpt4 book ai didi

vb.net - 操作数类型冲突 : nvarchar is incompatible with image

转载 作者:行者123 更新时间:2023-12-02 04:51:48 25 4
gpt4 key购买 nike

我正在使用 SQL Server 2008 存储过程来创建新记录这个语法:

cmd.Parameters.Add("@photo", DBNull.Value)
cmd.ExecuteNonQuery()

但结果是:

Operand type clash: nvarchar is incompatible with image 

照片不是唯一的参数,而是唯一的图像参数,我没有传递一个 nvarchar 但一个空值,我错过了什么吗?

最佳答案

如果您传入DBNull.Value 作为值,ADO.NET 无法确定该参数的类型。如果指定字符串或整数值,则可以从提供的值派生 SQL 参数的类型 - 但DBNull.Value 应该转换成什么类型​​??

传入 NULL 值时,您需要自己显式指定 SqlDbType:

Dim photoParam As New SqlParameter("@photo", SqlDbType.Image)
photoParam.Value = DBNull.Value
cmd.Parameters.Add(photoParam)

cmd.ExecuteNonQuery()

我希望这应该有效!

更新:在 C# 中同样的事情是:

SqlParameter photoParam = new SqlParameter("@photo", SqlDbType.Image);
photoParam.Value = DBNull.Value;
cmd.Parameters.Add(photoParam);

cmd.ExecuteNonQuery();

有一个很棒的、免费的、非常有用的VB.NET-to-C# converter out there - 使用它!

关于vb.net - 操作数类型冲突 : nvarchar is incompatible with image,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2420708/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com