Solved

Insert Byte Array into MSSQL

Posted on 2006-07-06
3
393 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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with Syntax 9 37
VB.Net - KeyPress Event 4 37
vb.net class 3 17
MailAddress in vb 4 16
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…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

821 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