The following sample code shows how to use BLOB data types with ScimoreDB.
The full source code of the sample project, which you can compile and execute, is located under http://www.scimore.com/download/2.5/BlobDemo.zip. The sample uses Scimore embedded database.
Suppose that we already have an established connection with a server.
ScimoreConnection connection;
ScimoreCommand command;
The code snippet showing how to insert an image into a BLOB field:
Bitmap image = SystemIcons.Warning.ToBitmap();
byte[] value = (byte[])TypeDescriptor.GetConverter(image).ConvertTo(image, typeof(byte[]));
command.CommandText = "INSERT INTO table_1 VALUES (@p1)";
ScimoreParameter p1 = new ScimoreParameter("p1", ScimoreDbType.Blob);
p1.Value = value;
command.Parameters.Add(p1);
int rowsAffected = command.ExecuteNonQuery();
And the following code snippet shows how to read data from a BLOB field
command.CommandText = "SELECT column_1 FROM table_1";
ScimoreDataReader reader = command.ExecuteReader();
while (reader.Read())
{
value = (byte[])reader["column_1"];
image = (Bitmap)TypeDescriptor.GetConverter(typeof(Bitmap)).ConvertFrom(value);
image.Save("warning.bmp");
}
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5