How to save byte array to database in vb.net

I have a byte array of a file and I need to store it in my database in a field that was dropped for an image of type.

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

"EXECUTE saved by proc @ parm1, @ parm2, @ parm3"

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

Hope this makes sense.

I also understand that I can create parameters in com objects, but I don't want to do that as it will break my entire data access class and I am not ready to do this at the moment.

Thanks for any help.

+2


source to share


2 answers


In SQL statements, you can use the hexadecimal notation "0x1323235 ..." to represent binary data, but this is not a good way to deal with it. You have to use parameters:



sqlCmd.Parameters.AddWithValue("@parameterName", byteArrayInstance)

      

+2


source


The answering question is about how to burn a byte array into a string. Convert byte array to string



byte[] b = new byte[100];
string s = System.Text.ASCIIEncoding.ASCII.GetString(b);

      

0


source







All Articles