Deleting binary data (image column) from sql server with ADO.NET

R

Ryan Taylor

Hello.

I have an ASP.NET application where I allow the user to upload attachments.
I upload the attachments as binary data to an image column in sql server. I
have managed to upload the data correctly. However, I need to be able to set
binary field back to NULL if the user wants to delete an attachmnet. What is
the proper way to do this? Thanks in advance.

I currently receive the following error.

Prepared statement '(@attachment nvarchar(4000), @attchmentMimeType
nvarchar(4000), @' expects a parameter @attachment, which was not supplied.

when I do the following.

string update = "UPDATE ResponseDetails SET attachment=@attachment, " +
"attachmentFileName=@attachmentFileName,
attachmentMimeType=@attachmentMimeType, " +
"lastModBy=@lastModBy, lastModUtcDate=@lastModUtcDate " +
"WHERE responseSessionId=@responseSessionId AND
questionId=@questionId";

SqlCommand sqlCmd = new SqlCommand(update, sqlConn);
sqlCmd.Parameters.Add("@attachment", DBNull.Value);



Or the error

Operand type clash: nvarchar is incompatible with image

when I do the following

string update = "UPDATE ResponseDetails SET attachment=@attachment, " +
"attachmentFileName=@attachmentFileName,
attachmentMimeType=@attachmentMimeType, " +
"lastModBy=@lastModBy, lastModUtcDate=@lastModUtcDate " +
"WHERE responseSessionId=@responseSessionId AND
questionId=@questionId";

SqlCommand sqlCmd = new SqlCommand(update, sqlConn);
sqlCmd.Parameters.Add("@attachment", null);




Ryan Taylor
 
G

Gary Morris

You might get a better response posting to a SQL newsgroup. If I knew
the answer, I would tell you though.
 
R

Ryan Taylor

A co-worker figured this one out. Simple really. The sql string became

string update = "UPDATE ResponseDetails SET attachment=null, " +
"attachmentFileName=null,
attachmentMimeType=null, " +
"lastModBy=@lastModBy, lastModUtcDate=@lastModUtcDate " +
"WHERE responseSessionId=@responseSessionId AND
questionId=@questionId";

Hard code the null values instead of trying to use parameterized lists.

-Ryan.
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top