// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Data; using System.IO; using System.Data.SQLite; namespace E { public class Program { public static void Main(string[] args) { File.Delete(@"C:\TestBlob.db"); using(SQLiteConnection con = new SQLiteConnection(@"Data Source=C:\TestBlob.db;Version=3;Password=hemmeligt;New=True")) { con.Open(); SQLiteCommand cre = new SQLiteCommand("CREATE TABLE tbl (id INTEGER NOT NULL, data BLOB, PRIMARY KEY(id))", con); cre.ExecuteNonQuery(); SQLiteCommand ins = new SQLiteCommand("INSERT INTO tbl VALUES(@id,@data)", con); ins.Parameters.Add("@id", DbType.Int32); ins.Parameters.Add("@data", DbType.Object); for(int i = 0; i < 3; i++) { ins.Parameters["@id"].Value = i + 1; byte[] b = new byte[(i + 1) * 100]; for(int j = 0; j < b.Length; j++) b[j] = (byte)((i + 1 + j) % 255); ins.Parameters["@data"].Value = b; ins.ExecuteNonQuery(); } SQLiteCommand sel = new SQLiteCommand("SELECT id,data FROM tbl", con); SQLiteDataReader rdr = sel.ExecuteReader(); while(rdr.Read()) { int id = (int)(long)rdr[0]; byte[] b = (byte[])rdr[1]; if(b.Length != id * 100) { throw new Exception("oops"); } for(int j = 0; j < b.Length; j++) { if(b[j] != (id + j) % 255) { throw new Exception("oops"); } } Console.WriteLine("id " + id + " is OK"); } rdr.Close(); } } } }