MilkBottle
MilkBottle

Reputation: 4332

How to store image in SqlCe Database for windows Phone

not sure how to do this since there is no ado.net in Windows Phone. Would appreciate if you can show me some code and sample.

Thanks

Upvotes: 3

Views: 4470

Answers (2)

ErikEJ
ErikEJ

Reputation: 41799

Use image data type, see this sample: http://erikej.blogspot.com/2009/11/how-to-save-and-retrieve-images-using.html

Upvotes: 2

Mo Valipour
Mo Valipour

Reputation: 13496

I would suggest to approaches:

1- If your images are not going to be very large, then you can store Base64 string of image data as a string field in database.

var base64String = Convert.ToBase64String(imageData); // and store this to database
var imageData = Convert.FromBase64String(imageDataString); // read image data from database

2- otherwise you can assign your image (or database record) a unique GUID and store your image in IsolatedStorageFile.

using (var isf = IsolatedStorageFile.GetUserStoreForApplication())
{
    using (var writer = new BinaryWriter(new IsolatedStorageFileStream(filename, System.IO.FileMode.Create, isf)))
    {
        writer.Write(imageData);
    }
}

will add code in a minute

Upvotes: 2

Related Questions