Null value in a parameter varbinary datatype

£可爱£侵袭症+ 提交于 2019-11-29 09:35:15
Rahul Tripathi

You can try something like this:-

cmd.Parameters.Add( "@Image", SqlDbType.VarBinary, -1 );

cmd.Parameters["@Image"].Value = DBNull.Value;

I dont know the reason why "DBNull.Value" does not work for me. And I figure out another solution can solve this problem.

cmd.Parameters["@Image"].Value = System.Data.SqlTypes.SqlBinary.Null;

try this :

mySqlCommand.Parameters.AddWithValue("@Image", new byte[]{});
sqlCommand.Parameters.AddWithValue("@image", SqlBinary.Null);

i do it like this without a problem

SqlParameter image= new SqlParameter("@Image", SqlDbType.VarBinary, System.DBNull.Value);
mySqlCommand.Parameters.Add(image);
yodhraj patil

Set null value in your Stored Procedure. Doesn't need to do anything else.

ex. @photo varbinary(max) = null,

ALTER PROCEDURE [dbo].[InsertOurTeam]
    @name nvarchar(50),
    @Sname nvarchar(50),
    @designation nvarchar(50),
    @photo varbinary(max) = null,
    @Pname nvarchar(50)=null,
    @psize bigint=null,
    @id int output
    AS
    BEGIN

        SET NOCOUNT ON;
        insert into OurTeam values (@name,@Sname,@designation,@photo,@Pname,@psize);

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