Insert NULL into SQL Server Image column

A

Alasdair Thomson

Hi,

I have a SQL Server database with a column of type "Image" that I am
using to store bitmaps. I am able to store and retrieve bitmaps from
C# using well documented methods on various internet sites but since
my bitmap is optional I also need the ability to insert a null into
this column.

Using the following code gives an error for an INSERT command:

sqlCmd.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Picture",
System.Data.SqlDbType.VarBinary, 2147483647, "Picture"));
sqlCmd.Parameters["@Picture"].Value = DBNull.Value;
sqlCmd.ExecuteNonQuery();

Upon the execute, I get the error

"An unhandled exception of type 'System.Data.SqlClient.SqlException'
occurred in system.data.dll
Additional information: System error."

Can somebody help me please and explain how it is possible to insert a
NULL into an Image column since the DBNull.Value does not appear to
work.

Kind Regards
Alasdair
 
A

Alasdair Thomson

Apologies all - please ignore, this was not the reason for the error - Doh!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top