SqlCE2.0, Blob and VB.NETCF

  • Thread starter Thread starter David Webb
  • Start date Start date
D

David Webb

Hi,

Does anyone have any sample code of inserting/retrieving a Bitmap from
an SQLCE2.0 Blob field?

Regards,

David.
 
Something like this:
Here the SigData table has a column Signature of type Image. This column contains full .bmp file data. Notice that there is an issue of creating a BMP file out of Bitmap object. Basically it is not possible without taking some drastic measures (http://www.opennetcf.org/Articles/GdiObjects.asp). It is rather easy to do if you capture parts of the screen using Windows API

Retrieving:

SqlCeCommand cmd = GlobalClass.Global.Connection.CreateCommand();
cmd.CommandText = "select Signature from SigData where id = " + ID.ToString();
SqlCeDataReader rdr = cmd.ExecuteReader();
if ( rdr.Read() )
{
MemoryStream ms = new MemoryStream(rdr.GetSqlBinary(0).Value);
Bitmap bm = new Bitmap(ms);
pbSignature.Image = bm; // pbSIgnature is a picturebox
}

Inserting:

SqlCeCommand cmd = myConnection.CreateCommand();
cmd.CommandText = string.Format("insert into SigData (id, Signature) values( ?, ? )");
cmd.Parameters.Add("id", SqlDbType.Int).Value = ID;
byte[] Sig;
// Populate the array with the byte representation of the image
// How to do it is a subject for a separate discussion
...
//
SqlCeParameter param = cmd.Parameters.Add("Signature", SqlDbType.Image, Sig.Length);
param.Value = Sig;
cmd.ExecuteNonQuery();
 
Hi Alex,

Thanks for your reply. I have the bitmap already as a file in the local
directory. I want to insert the bitmap into a Blob field in an SQLCE 2.0
DB using VB.NET CF. I don't need to capture anything from the screen as
I've done that already. Would you have any code snippets at all?

Regards,

David.
 
Back
Top