?
Solved

Insert Byte Array into MSSQL

Posted on 2006-07-06
3
Medium Priority
?
397 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 2000 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

Industry Leaders: 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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month7 days, 19 hours left to enroll

765 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