Solved

Insert Byte Array into MSSQL

Posted on 2006-07-06
3
396 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

724 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