473,765 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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), @attchmentMimeT ype
nvarchar(4000), @' expects a parameter @attachment, which was not supplied.

when I do the following.

string update = "UPDATE ResponseDetails SET attachment=@att achment, " +
"attachmentFile Name=@attachmen tFileName,
attachmentMimeT ype=@attachment MimeType, " +
"lastModBy=@las tModBy, lastModUtcDate= @lastModUtcDate " +
"WHERE responseSession Id=@responseSes sionId AND
questionId=@que stionId";

SqlCommand sqlCmd = new SqlCommand(upda te, sqlConn);
sqlCmd.Paramete rs.Add("@attach ment", DBNull.Value);

Or the error

Operand type clash: nvarchar is incompatible with image

when I do the following

string update = "UPDATE ResponseDetails SET attachment=@att achment, " +
"attachmentFile Name=@attachmen tFileName,
attachmentMimeT ype=@attachment MimeType, " +
"lastModBy=@las tModBy, lastModUtcDate= @lastModUtcDate " +
"WHERE responseSession Id=@responseSes sionId AND
questionId=@que stionId";

SqlCommand sqlCmd = new SqlCommand(upda te, sqlConn);
sqlCmd.Paramete rs.Add("@attach ment", null);


Ryan Taylor
Nov 18 '05 #1
2 2810
You might get a better response posting to a SQL newsgroup. If I knew
the answer, I would tell you though.

"Ryan Taylor" <rt*****@stgeor geconsulting.co m> wrote in message
news:es******** ******@TK2MSFTN GP15.phx.gbl...
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), @attchmentMimeT ype
nvarchar(4000), @' expects a parameter @attachment, which was not supplied.
when I do the following.

string update = "UPDATE ResponseDetails SET attachment=@att achment, " +
"attachmentFile Name=@attachmen tFileName,
attachmentMimeT ype=@attachment MimeType, " +
"lastModBy=@las tModBy, lastModUtcDate= @lastModUtcDate " +
"WHERE responseSession Id=@responseSes sionId AND
questionId=@que stionId";

SqlCommand sqlCmd = new SqlCommand(upda te, sqlConn);
sqlCmd.Paramete rs.Add("@attach ment", DBNull.Value);

Or the error

Operand type clash: nvarchar is incompatible with image

when I do the following

string update = "UPDATE ResponseDetails SET attachment=@att achment, " +
"attachmentFile Name=@attachmen tFileName,
attachmentMimeT ype=@attachment MimeType, " +
"lastModBy=@las tModBy, lastModUtcDate= @lastModUtcDate " +
"WHERE responseSession Id=@responseSes sionId AND
questionId=@que stionId";

SqlCommand sqlCmd = new SqlCommand(upda te, sqlConn);
sqlCmd.Paramete rs.Add("@attach ment", null);


Ryan Taylor

Nov 18 '05 #2
A co-worker figured this one out. Simple really. The sql string became

string update = "UPDATE ResponseDetails SET attachment=null , " +
"attachmentFile Name=null,
attachmentMimeT ype=null, " +
"lastModBy=@las tModBy, lastModUtcDate= @lastModUtcDate " +
"WHERE responseSession Id=@responseSes sionId AND
questionId=@que stionId";

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

-Ryan.
Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
414
by: PearCZ | last post by:
Hi, I am trying to store binary data (e. g. image) in MS SQL Server 2000 column which data type is . I understand I could store binary data easily in MS SQL type but I have only column available in the database which I don't want to change. I think the trouble is in .net data type string which actually is a unicode string. I have an array of bytes (= binary data) which I need to pass somehow to the stored procedure which input...
1
3743
by: Altemir | last post by:
I have a table that contains the following two columns: BITS (image(16)) BIT_LENGTH (int(4)) When I look at the table, I see "OLE Object" in the BITS column. What syntax should I use in a SELECT statement to convert the binary image info contained in "BITS" into simple text that I can read? What role does the BIT_LENGTH field play?
1
3519
by: Bassem | last post by:
Hi all I saved my imaged in SQL 2000 server database and now I want to get the values of the columns to text or xml file. The field I didn't could get it to the text file is the Image column (binary array value). Is there any solution to be able to save the binary array to a text or xml file?
3
2098
by: Josema | last post by:
Hi to all, I have stored in a database some binary files (pdfs, and gif images), i would like to know how could i show it, in internet explorer when a person enters for instance in a textbox the id of the file that want to view.... This is my Sql table... ID int File binary
3
2743
by: Simon Harris | last post by:
Hi All, I have a data grid which displays country names. I now wish to display the country flag images above the names. Can someone please advise how I display an image in a datagrid? I have a folder of flag images, named in relations to the countries database ID. Current data grid code is...
6
2729
by: | last post by:
Hi all, is there a better way to stream binary data stored in a table in sql 2005 to a browser in .net 2.0? Or is the code same as in .net 1.1? We noticed that in certain heavy load scenarios, every now and then the client would timeout and have to re-initiate the request... TIA!
15
9808
by: mleaver | last post by:
I want to open a second window and display a binary image that is returned from a java program via XMLRPC. The data returned is a binary encoded base64 png file. If I write the data out to a file on my server, I can display it using the following javascript: var windowHandle = window.open('about:blank','windowName','width=250,height=250'); windowHandle.document.write('<img name="myImage" src="images/test.png">');
62
17851
by: ivan.leben | last post by:
How can I really delete a preloaded image from memory/disk cache? Let's say I preload an image by creating an Image object and setting its src attribute to desired URL: var img = new Image(); img.src = ; Then I use the image a few more times by adding it into an Array object:
5
3245
by: raptureathand | last post by:
How can i binary serialize objects on MySQL also can you provide a step by step approach of running the program below and which software and platform do i need to get the program working; using MySql.Data.MySqlClient; private string imagePath = string.Empty; private string MySqlConnString = "Server = localhost; Uid = root; Pwd = password; Database = demo;";
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9399
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10163
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9957
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9835
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5276
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.