If you pass in DBNull.Value
as the value, ADO.NET can't figure out what type the parameter should be. If you specify a string, or an integer value, the type of the SQL parameter can be derived from the value provided - but what type should DBNull.Value
be turned into??
When passing in a NULL value, you need to specify that SqlDbType
yourself, explicitly:
Dim photoParam As New SqlParameter("@photo", SqlDbType.Image)
photoParam.Value = DBNull.Value
cmd.Parameters.Add(photoParam)
cmd.ExecuteNonQuery()
That should work, I hope!
Update: same thing in C# would be:
SqlParameter photoParam = new SqlParameter("@photo", SqlDbType.Image);
photoParam.Value = DBNull.Value;
cmd.Parameters.Add(photoParam);
cmd.ExecuteNonQuery();
There's a great, free, very useful VB.NET-to-C# converter out there - use it!