tags:

views:

119

answers:

2

I have a byte array of a file and I need to save it into my database in a field that has been set aside of type image.

However I have a problem my data access class takes a sql string and commits it to the database for example.

"EXECUTE stored proc @parm1, @parm2, @parm3"

However the problem is I cannot figure out how to transfer the byte array to string so that I can add it as an argument.

I hope this make sense.

I also understand that I can build parameters in com objects but I do not want to do this as it will disrupt my whole data access class and I am not prepared to do this at the moment.

Thanks for any help.

+2  A: 

In SQL statements, you can use the hexadecimal notation "0x1323235..." to represent binary data but it's not really a good way to deal with it. You should be using parameters:

sqlCmd.Parameters.AddWithValue("@parameterName", byteArrayInstance)
Mehrdad Afshari
A: 

Answering question of how to burn byte array into a string. Convert the byte array to a string

byte[] b = new byte[100];
string s = System.Text.ASCIIEncoding.ASCII.GetString(b);
Gratzy
That is a way to convert a byte array to a string, but it is completely unusable in this context.
recursive
The poster's original question was how to turn the byte array into a string because that was what the argument to his data access class was and he specified he didn't want to use parameters.
Gratzy