Visual C++, System.Data.SQLite - Retrieve image from database

Hi,

I am attempting to retrieve an image stored as a BLOB in a SQLite database and display that image in a Windows Form PictureBox control.

By inspecting my program in debug, I have concluded that I can retrieve the correct BLOB and store it in a System::Object ^ (which is the return type of the ExecuteScalar() method). However, I have no idea what to do with this System::Object; even though it contains the right data, I cannot convert it to anything useful, like a char array or System::Drawing::Image.

This is what I have so far:

 
System::Object ^ obj = cmd->ExecuteScalar();


What can I do with obj to get my image on a Windows Form? Just trying to cast it as a char array or image is resulting in casting errors.
For C++/CLI it is best if you ask @ the MSDN Forums.
Thanks! But actually, I lucked out and came across the answer.

Just in case anyone stumbles across this thread:

1
2
3
4
5
6
7
8
9
10
11
		System::Object ^ obj = cmd->ExecuteScalar();
		Image ^ img;

		// http://www.digitalcoding.com/Code-Snippets/CPP-CLI/C-CLI-Code-Snippet-Get-Image-from-sql-server.html
        array<System::Byte> ^_ImageData = gcnew array<System::Byte>(0);
        _ImageData = safe_cast<array<System::Byte>^>(obj);
        System::IO::MemoryStream ^_MemoryStream = gcnew System::IO::MemoryStream(_ImageData);
        img = System::Drawing::Image::FromStream(_MemoryStream);
		con->Close();
		return img;
Topic archived. No new replies allowed.