Solved

Insert Byte Array into MSSQL

Posted on 2006-07-06
3
395 Views
Last Modified: 2012-08-13
Hi,

I have a byte array that need to be inserted into a MS SQL database but i do not know how to make the sql query to do this. Also it needs to be a query string not a parameter.

Can anyone help?
0
Comment
Question by:cossy74
3 Comments
 
LVL 11

Expert Comment

by:LordWabbit
ID: 17056923
You have to pass the byte array as a parameter, eg
UPDATE myTable SET myCol = @myArray WHERE BLAH DE BLAH
and then add the @myArray param to the command object
myCommand.Parameters.AddWithValue("@myArray", byteMe)

The only other way would be to mime encode it and then pass it inline, but then that would kind of defeat the purpose since you would have to un mime encode it before using it again.  Why don't you want to use parameters?  Your SQL Code can still be inline instead of a stored proc.  Also mime encoding will increase the size of the byte array by around 30% (depending).
0
 

Author Comment

by:cossy74
ID: 17069887
LordWabbit: It needs to be a query string not using parameters. Currently i have a class that reads the information from the databse into structures. I can read and display the 'image' fields without mime encoding but i cannot update the 'image' fields. What i need is code to do this and everything i find is not working out. The question is how can this be done. There must be a way of formulating a sql query and passing the query to the database.
0
 
LVL 24

Accepted Solution

by:
Jeff Certain earned 500 total points
ID: 17075806
Cossy,

You'll find that most of the experts are advocates of stored procedures and parameters (even for dynamic SQL). There's a few reasons for this. Mostly, it has to do with things like not having to keep track of single quotation marks, data types, and preventing SQL injection attacks. But, hey... what do we know?

In general, you'll also find that storing images (particularly large images) in your database will cause some serious performance issues. For a discussion about the pros and cons of storing BLOBs in your database, here's a link to someone who knows more avout htis stuff than pretty much anyone:
http://www.dotnetslackers.com/XML/re-33662_All_about_storing_binary_blobs_in_the_database.aspx



0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question