| DotNetFirebird Using Firebird SQL in .NET. |
|
Home
Features
Download
Documentation
Developer's Documentation
Connection String Parameters
Using FbConnectionStringBuilder to Build a Connection String
Connection Pooling
Create a New Database From an SQL Script
Using FbDataAdapter to Fill a Dataset
Firebird and .NET Framework Data Types Mapping
BIGINT Reading Example (C#)
BLOB Reading Example (C#)
BLOB SUB_TYPE 1 Reading Example (C#)
CHAR Reading Example (C#)
DATE Reading Example (C#)
DECIMAL Reading Example (C#)
DOUBLE PRECISION Reading Example (C#)
FLOAT Reading Example (C#)
INTEGER Reading Example (C#)
NUMERIC Reading Example (C#)
SMALLINT Reading Example (C#)
TIME Reading Example (C#)
TIMESTAMP Reading Example (C#)
VARCHAR Reading Example (C#)
Transaction Isolation Levels
Embedded Firebird Documentation
Performance Tuning
Security
Administration
Migration to Firebird
Sample Code
FAQ
Tools and Code
About
Blog
|
BLOB Reading Example (C#)TEST.SQL Script (Testing Database)Run the following script to create the testing database. It creates a simple table called MYTABLE with a single row. (How to create a database from an SQL script): CREATE TABLE MYTABLE (
ID INTEGER,
VAL BLOB SUB_TYPE 0 SEGMENT SIZE 80
);
Reading valuesBecause it is not possible to insert binary BLOB value in the SQL script we need to insert it in the code before reading. The following sample prints the values from the column "VAL" to console: string database = "test.fdb";
CreateEmbeddedDb(database, "test.sql");
FbConnectionStringBuilder csb = new FbConnectionStringBuilder();
csb.ServerType = 1;
csb.Database = database;
using (FbConnection c = new FbConnection(csb.ToString()))
{
c.Open();
FbCommand cmdInsert = new FbCommand("INSERT INTO mytable(id, val) VALUES(@id, @val)", c);
cmdInsert.Parameters.Add("@id", 1);
cmdInsert.Parameters.Add("@val", new byte[] {1, 2, 3});
cmdInsert.ExecuteNonQuery();
FbCommand cmd = new FbCommand("SELECT val FROM mytable", c);
using (FbDataReader r = cmd.ExecuteReader())
{
while (r.Read())
{
int size = 20;
byte[] bytes = new byte[size];
long count = r.GetBytes(0, 0, bytes, 0, size);
for(int i = 0; i < count; i++)
Console.WriteLine("Value: " + bytes[i]);
}
}
}
Copyright © 2005 - 2007 DotNetFirebird |