I want to store image in a SQL Server database. I have converted image to byte array, and the data type of column in database is varbinary(MAX) but it didn't work even I have changed its type to Image but I get the same results.
I have followed many links from stackoverflow, code project, dream in code but couldn't find my solution there is my code for inserting byte array in database
string query = @"INSERT INTO myTable (ID, byteArray, DateTime) VALUES (@ID, @byteArray, @datetime)";
try
{
command = new SqlCommand(query, base.conn);
command.Parameters.AddWithValue("@ID", id);
command.Parameters.AddWithValue("@byteArray", ss); // ss is byte[] from arguments
command.Parameters.AddWithValue("@datetime", DateTime.Now);
base.Open();
if (command.ExecuteNonQuery() > 0)
{
base.Close();
return true;
}
else
{
base.Close();
return false;
}
}
catch (SqlException ex)
{
base.Close();
return false;
}
I have also tried it with
command = new SqlCommand(query, base.conn);
command.Parameters.Add("@ID", id);
command.Parameters.Add("@byteArray", ss); // ss is byte[] from arguments
command.Parameters.Add("@datetime", DateTime.Now);
and the thing it will store in database

but it will show the value in 3rd column as <Binary data> what is that???