开发者

Retreving an image stored on SQl Server CE 3.1

I'm developing a WinForm app for Windows Mobile 6.0 with C#, .NET Compact Framework 2.0 SP2 and SqlServer CE 3.1.

I have this code that is not working:

using (SqlCeDataReader reader = cmd.ExecuteReader())
{
    if (reader.Read())
    {
        //read the signature from the database
开发者_StackOverflow中文版        long imgSize = reader.GetBytes(0, 0, null, 0, 0);
        image= new byte[imgSize];
        reader.GetBytes(0, 0, image, 0, 0);
    }
}

I think there is a problem obtaining all data stored on the column containing bytes from the image.

When I do this:

bitmapImage = new Bitmap(new MemoryStream(image));

I'm getting an OutOfMemoryException.

But if I use a TableAdapter to obtain the image it works perfectly.

What I'm doing wrong?

Thanks.


Try this instead:

var ms = new MemoryStream(image)
bitmapImage = new Bitmap(ms);
// dont close the memorystream

Update

The problem lies with

reader.GetBytes(0, 0, buffer, 0, 0);

Clearly it needs to be more than 0 bytes in length (last parameter).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜