Check the documentation for
ExecuteScalar()
:
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executescalar.aspx[
^]
"Executes the query, and returns the first column of the first row in the result set returned by the query. Additional columns or rows are ignored"
Your query is:
string sql = "SELECT ProductName, ProductImage FROM image WHERE ImageID = @ImageID";
Which means you're trying to cast ProductName to a
byte[]
Either amend your query to:
string sql = "SELECT ProductImage FROM image WHERE ImageID = @ImageID";
or think about using an ORM like an ADO.net DataSet or Entity Framework model if you need to return more than just the ProductImage column.