Set up a varbinary or image column in your database.
Then just insert it:
using (SqlConnection con = new SqlConnection(strConnect))
{
con.Open();
byte[] bytes = GetTheByteData();
using (SqlCommand com = new SqlCommand("INSERT INTO myTable (myBinaryDataColumnName) VALUES (@BINDATA)", con))
{
com.Parameters.AddWithValue("@BINDATA", bytes);
com.ExecuteNonQuery();
}
}
To extract it:
byte[] bytes;
using (SqlConnection con = new SqlConnection(strConnect))
{
con.Open();
using (SqlCommand com = new SqlCommand("SELECT myBinaryDataColumnName FROM myTable", con))
{
using (SqlDataReader reader = com.ExecuteReader())
{
if (reader.Read())
{
bytes = (byte[]) reader["myBinaryDataColumnName"];
}
}
}
}
Obviously, you will want to filter the returned values with a WHERE clause on the SELECT statement to just retrieve the one you are interested in.