Solved

Insert Byte Array into MSSQL

Posted on 2006-07-06
3
391 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now