Why use Bytes instead of using Image? What is the best practice?

6

I'd like to know why to use the data type Bytes instead of using Image itself. If the SQL Server database has the Image data type, then it should be easier and more convenient to insert it in Image right mode?

I would like an example of how to get the form image and save it to a SQL Server database, and then retrieve it to a View.

    
asked by anonymous 10.02.2014 / 19:25

2 answers

8

I see some reasons for this. The first of these is that the Image data type will be removed in any future version of SQL Server. (Html ) The ntext, text, and image data types will be removed in a future release of Microsoft SQL Server

The Image of the System.Drawing library is not equivalent to the Image field of the Sql Server, and did not do any "mapping" to it. I agree that it would even be simpler though, it is not difficult to convert an image to an array of bytes:

public byte[] imageToByteArray(System.Drawing.Image imageIn)
{
    MemoryStream ms = new MemoryStream();
    imageIn.Save(ms,System.Drawing.Imaging.ImageFormat.Gif);
    return  ms.ToArray();
}

System.Drawing.Imaging.ImageFormat.Gif you replace with whatever shape your image is. (MSDN) Image Formats . I removed this code from StackOverflow.com (question 17352061)

In addition, this image field contains nothing more than Dados binários do comprimento variável de 0 a 2^31-1 (2.147.483.647) bytes. , as the first msdn link that I sent you cites.

I hope I have helped. As for the example, give it a google search, it is very easy to find.

    
10.02.2014 / 19:44
0

Another solution is not to save blobs in the database in any way. This is especially good for performance when you upload / download large files. From experience I have seen that it is much more efficient to save the files to a repository and just save a link / path to it.

    
11.02.2014 / 11:30