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.

1
  • in what datatype are you trying to store it? I would do it in varbinary and then use Mehrdad's answer. Commented Oct 27, 2009 at 3:37

2 Answers 2

2

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)
Sign up to request clarification or add additional context in comments.

Comments

0

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);

2 Comments

That is a way to convert a byte array to a string, but it is completely unusable in this context.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.