using System; using System.Collections; using System.Collections.Generic; using System.Data.SQLite; using System.Text; namespace Program { public class Init { static void Main(string[] args) { using (Data data = new Data()) { Console.WriteLine(data.find(5, "ProbNMB", "probability")); } } } public class Data : IDisposable { private SQLiteConnection conn; private SQLiteCommand stmt; private SQLiteDataReader reader; public Data() { conn = new SQLiteConnection("data source=sugammadex.db;version=3"); stmt = new SQLiteCommand(conn); conn.Open(); } public object find(int id, string table, string return_column) { stmt.CommandText = string.Format("select {0} from {1} where id = {2}", return_column, table, id); using (reader = stmt.ExecuteReader()) { try { return reader[return_column]; } catch (SQLiteException ex) { throw new SQLiteException("Statement invalid.", ex); } } } public object find(string conditions, string table, string return_column) { stmt.CommandText = string.Format("select {0} from {1} where {2}", return_column, table, conditions); using (reader = stmt.ExecuteReader()) { try { return reader[return_column]; } catch (SQLiteException ex) { throw new SQLiteException("Statement invalid.", ex); } } } public void Dispose() { conn.Close(); Dispose(true); } /// /// An overridable Dispose method to allow subclasses to add their /// own dispose routines /// /// protected virtual void Dispose(bool disposing) { // tidy managed resources if ( disposing ) { if ( reader != null ) { reader.Dispose(); reader = null; } if ( conn != null ) { conn.Dispose(); conn = null; } } // tidy unmanaged resources else { // no unmanaged resources, do nothing } } } }