I have a byte array highlighted below, how do I insert it into a SQL Server database Varbinary column?
byte[] arraytoinsert = new byte[10]{0,1,2,3,4,5,6,7,8,9};
string sql =
string.format
(
"INSERT INTO mssqltable (varbinarycolumn) VALUES ({0});",WHATTODOHERE
);
My solution would be to use a parameterised query, as the connectivity objects take care of formatting the data correctly (including ensuring the correct data-type, and escaping “dangerous” characters where applicable):
Edit: Added the wrapping “using” statement as suggested by John Saunders to correctly dispose of the SqlCommand after it is finished with