Saving an Image in SQL Server CE Database

Does anyone know an example of storing an image in a SQL Server CE database?

What type of data should the column be? (I guess the binary.)

I am using Linq-To-Datasets. Can I use this to put an image in a database and pull it out later?

Thanks for any advice.


Here is how I did it:

MemoryStream stream = new MemoryStream(); myBitmapImage.Save(stream, ImageFormat.Png); myInsertLinqToDataSetRow.IMAGE_COLUMN = stream.ToArray(); 

To download it back, I did the following:

 MemoryStream stream = new MemoryStream(myLinqToDataSetRow.IMAGE_COLUMN); myBitmapImage.SignatureImage = new Bitmap(stream); 

I found a page on MSDN that said the "Image" column type was leaving and that you should use varbinary (MAX). Max is not supported by SQL Server CE, so I did varbinary (8000).

LATER NOTE: although varbinary (max) is not supported by SQL Server CE. Varbinary (8000) is not enough for many images. In the end, I used the image type, although it is not recommended. After ms offers a resonant alternative on a mobile platform, I will consider switching.

+6
c # windows-mobile sql-server-ce compact-framework linq-to-dataset
source share
3 answers

Here is an MSDN article explaining how:

http://support.microsoft.com/kb/318639

Unfortunately, the example is in VB, but I'm sure you can get an idea of ​​how to do this.

I would say that a binary data type would be good for storing images.

+5
source share

Why aren't you using image type? Here is a description of the types supported by sql ce server.

Image - binary data of variable length with a maximum length of 2 ^ 30 - 1 (1,073,741,823 bytes).

+5
source share

This is not a direct answer to your question, but I had good success by saving the path to the image file (example: C: \ images \ image1.png) as a string value in the database instead of the raw image.

One of the advantages of this is that it reduces the size of the database.

Another is that multiple tables can point to images without saving multiple copies of the image.

+1
source share

All Articles